开发者

PHP Form Validation Regular Expression, no symbols or numbers

Ok I am trying to get the users First Name

the form gets their name perfectly fine and posts it into a variable.

Now I am trying to do error checking

else if(!preg_match("/^[\w-]+$/", $firstNameSignup)) {
       $firstNameSignupError = "Your first name cannot contain numbers or symbols, you entered " . $firstNameSignup;
       $firstNameSignup = "";
      }

I tried the above code and it does not like me but my if statement

if(!isset($firstNameSignup) || $firstNameSi开发者_JS百科gnup == "") {
   $firstNameSignupError = "You must enter your first name";
  }

works fine so I know that the error is in that else if statement... most likely in my regular expression

any help??? I'm totally at a loss (really new to PHP and regular expressions)

Thanks Shelby


else if(preg_match('#[^a-z]+$#i', $firstNameSignup)) {
            $firstNameSignupError = "Your first name cannot contain numbers or symbols, you entered " . $firstNameSignup;
            $firstNameSignup = "";
        }

finally found at that the above code worked


Preg match returns FALSE on error.

You need to do like so;

else if(preg_match("/^[\w-]+$/", $firstNameSignup) == 0) { // no matches

http://au2.php.net/preg_match

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜