cooldude832 Posted January 7, 2008 Share Posted January 7, 2008 I am trying to make sure passwords are only alphanumeric so I have <?php $pattern = "[^A-Za-z0-9]"; if(eregi($values['password'],$pattern)){ $errors[] = "The <b>password</b> can only contain alphanumeric characters."; } ?> so that should return an error if it finds a non Alphanumeric string, but it fails any ideas? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted January 7, 2008 Share Posted January 7, 2008 I don't know about ereg but preg would be $pattern = "/[^A-Za-z0-9]+/"; if(preg_match($pattern,$values['password'])){ $errors[] = "The <b>password</b> can only contain alphanumeric characters."; } Quote Link to comment Share on other sites More sharing options...
dsaba Posted January 7, 2008 Share Posted January 7, 2008 <?php $pat = '[a-zA-Z0-9]+'; $str = 'hello23489jhksgjl'; if (ereg($pat, $str)) { echo 'it is alphanumeric!'; } else { echo 'no its not alphanumeric!'; } ?> Tested: http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=2k3octs2 Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 8, 2008 Share Posted January 8, 2008 why do people keep on looking regex when there is predefine function that might match letters numbers and email people keep on asking how to match letters numbers etch.. and they get regex solution OK LOOK at ctype data they might what you're looking for I don't know about ereg but preg would be $pattern = "/[^A-Za-z0-9]+/"; if(preg_match($pattern,$values['password'])){ $errors[] = "The <b>password</b> can only contain alphanumeric characters."; } <?php $pat = '[a-zA-Z0-9]+'; $str = 'hello23489jhksgjl'; if (ereg($pat, $str)) { echo 'it is alphanumeric!'; } else { echo 'no its not alphanumeric!'; } ?> Tested: http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=2k3octs2 Quote Link to comment Share on other sites More sharing options...
dsaba Posted January 8, 2008 Share Posted January 8, 2008 that's a good suggestion teng, but why we answered in regex solutions was because this was his question Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 8, 2008 Share Posted January 8, 2008 that's a good suggestion teng, but why we answered in regex solutions was because this was his question yes but i guess better to point to better solution. i always see threads asking for regex and get an regex solution but in fact that is doable using sting function etc.. @dsaba i dont mean anything about this post hope you see my point thanks Ronald(teng) 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.