joecooper Posted August 26, 2011 Share Posted August 26, 2011 Hi, Im trying to check if this string only contains a-z A-Z and 0-9, but i am not sure it works if(preg_match("/(A-Z][a-z][0-9]/", $payoutaddress)){ echo("Address not valid!"); }else{ } It will always process the else. but even with other characters it will do the same Quote Link to comment https://forums.phpfreaks.com/topic/245765-checking-string-for-alphaumeric/ Share on other sites More sharing options...
Maq Posted August 26, 2011 Share Posted August 26, 2011 Why don't you just use - http://www.php.net/manual/en/function.ctype-alnum.php Quote Link to comment https://forums.phpfreaks.com/topic/245765-checking-string-for-alphaumeric/#findComment-1262309 Share on other sites More sharing options...
skwap Posted August 26, 2011 Share Posted August 26, 2011 take this example. <?php $string = "abcd"; // the data you want to validate. if(ctype_alnum($string)) // checking if the string contain alpha numeric characters. { echo "Success"; // do something what you want. } else { echo "Error"; // do something. } ?> ; Quote Link to comment https://forums.phpfreaks.com/topic/245765-checking-string-for-alphaumeric/#findComment-1262349 Share on other sites More sharing options...
codefossa Posted August 26, 2011 Share Posted August 26, 2011 As said, you can use alnum but just so you know, the regex would be more like '/[^a-z0-9]/i' and if it matches, it's not alphanumeric, and if it returns false, then it is. Quote Link to comment https://forums.phpfreaks.com/topic/245765-checking-string-for-alphaumeric/#findComment-1262350 Share on other sites More sharing options...
joecooper Posted August 28, 2011 Author Share Posted August 28, 2011 thanks thats working! Quote Link to comment https://forums.phpfreaks.com/topic/245765-checking-string-for-alphaumeric/#findComment-1262861 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.