astralaaron Posted November 21, 2008 Share Posted November 21, 2008 can someone please tell me why this isnt working? $firstName = 'asdf123'; if(!preg_match('/[a-zA-Z]/', $firstName)) { die('test'); } Link to comment Share on other sites More sharing options...
Ingolme Posted November 21, 2008 Share Posted November 21, 2008 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 More sharing options...
astralaaron Posted November 21, 2008 Author Share Posted November 21, 2008 i want it to be letters only Link to comment Share on other sites More sharing options...
astralaaron Posted November 21, 2008 Author Share Posted November 21, 2008 isnt the ! saying if its NOT lower case or upper case letters? Link to comment Share on other sites More sharing options...
Ingolme Posted November 21, 2008 Share Posted November 21, 2008 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 More sharing options...
aalbetski Posted November 21, 2008 Share Posted November 21, 2008 /^[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 More sharing options...
astralaaron Posted November 21, 2008 Author Share Posted November 21, 2008 thanks guys Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.