PDA

View Full Version : Regex help


Ziki
10-17-2008, 12:22 PM
Hello,

I am just learning some of the regular expressions and I would like to make a code to check if the specific field contains two words.It is to check if the user entered his first and last name not only his first name.Is there also a way to check if the two words are the same?And maybe combine these two so they can be added into the vb custom field regex?

Thank you very much!

Dismounted
10-18-2008, 10:25 AM
<a href="http://www.regular-expressions.info/tutorial.html" target="_blank">http://www.regular-expressions.info/tutorial.html</a>

That is probably a good starting point to learn regex.

Ziki
10-19-2008, 05:13 PM
Yes,but I am not very familiar with regex yet,and I was hoping for a specific code :)

Eikinskjaldi
10-20-2008, 02:10 AM
If you are looking for specific words then regex is not necessary. You only need it when looking for patterns (like words containing "abc")

For exact string matches you should use the php exact string functions (of which there are a bunch, and any php documentation will have them).

To check if the field contains two words I would use explode and then check that the array contains two elements. Seeing if they are the same is just a matter of
if ($names[0] == $names[1])..... (though you might like to correct for case insensitivity)

Ziki
10-20-2008, 10:34 AM
Oh yes,good idea :) thank you.