SyncViews Posted December 16, 2007 Share Posted December 16, 2007 Ive got this validation code function valid($string, $type) { switch ($type) { case "name": $allowed = preg_match("|^[A-Z0-9\ _]{3,16}$|i", $string); break; case "password": $allowed = preg_match("|^[A-Z0-9_]{6,40}$|i", $string); break; case "email": $allowed = preg_match("|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z.]{2,6}$|i", $string); break; } return ($allowed); } 1) For the password one. How do I make it so it allows 6 or more charecters? 2)For e-mails it always returns false. Why is this? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 16, 2007 Share Posted December 16, 2007 Q1: Use {6,} instead of {6,40} Q2: A-Z will only accept uppercase characters (that's actually a "bug" in all the regular expressions in your code (unless of course you only want your users' passwords and usernames to have uppercase characters, underscore and numbers)). You need to specify both the uppercase characters and lowercase characters (i.e. a-zA-Z). Quote Link to comment Share on other sites More sharing options...
SyncViews Posted December 16, 2007 Author Share Posted December 16, 2007 Isn't the "|i" meant to make it case insensitive though? Anyway I changed it to "$allowed = preg_match("|^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$|i", $string);" but it still returns false every time Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 16, 2007 Share Posted December 16, 2007 Isn't the "|i" meant to make it case insensitive though? Hmm... yeah, you're right... didn't notice that. There are a number of different regular expressions for emails you can use here though: http://www.regular-expressions.info/email.html Quote Link to comment Share on other sites More sharing options...
SyncViews Posted December 16, 2007 Author Share Posted December 16, 2007 The one I got from that p[age is basicle the same as mine and still isn't working for me mine: $allowed = preg_match("|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$|i", $string); the one I made useing the sites examples: $allowed = preg_match("|$[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$|i", $string); Mayby it's my php code? But if thats the case whyt would both the user name and password ones work... Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 16, 2007 Share Posted December 16, 2007 I just tested my own email on your function. It works fine for me. Are you testing with some non-standard email or something? Quote Link to comment Share on other sites More sharing options...
didgydont Posted December 17, 2007 Share Posted December 17, 2007 this one works good eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.