Jump to content

simple preg


astralaaron

Recommended Posts

Because all you're doing is asking the program to make sure there's at least one character between a and Z. And there is, so the conditon is false.I think what you want is this:

if(preg_match('/[^a-zA-Z]/', $firstName)) {die('test');}

Link to comment
Share on other sites

Well, the regular expression I gave you will make the condition true as long as there are characters that aren't letters. Which is what I thought you wanted.The "!" in your last expression was making the condition say "As long as you don't find a single letter"

Link to comment
Share on other sites

/^[a-zA-Z]$/this will return null (or false) if anything other than a letter is found in the string^ - beginning of string$ - end of stringthe ^ as the first character after the [ negates the class so [^a-zA-Z] will be true for everything that is not a letter

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...