开发者

PHP Form Validation Regular Expression, no symbols or numbers

开发者 https://www.devze.com 2022-12-24 04:36 出处:网络
Ok I am trying to get the users First Name the form gets their name perfectly fine and posts it into a variable.

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

精彩评论

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

关注公众号