oracle259 Posted October 31, 2006 Share Posted October 31, 2006 I have the following regex in my script that is supposed to allow only numbers and letters but for some reason it keeps allowing symbols #$%^*. etcHow can i stop this[code]$pattern = "/^(?=.*?[0-9])(?=.*?[a-zA-Z])[a-zA-Z0-9]*$/i"; $is_pattern = preg_match($pattern, $hash); if (!$is_pattern) { echo $is_pattern." Failure"; } else { echo $is_pattern." Pass"; }[/code] Link to comment https://forums.phpfreaks.com/topic/25745-regex-problem/ Share on other sites More sharing options...
sinisake Posted October 31, 2006 Share Posted October 31, 2006 I don't know why your code doesn't work but for same thing i rather use something like this:[code]<?php$text="sg ";if(eregi("[^a-z 0-9]",$text)){echo "NO-the string contains illegal characters!";}else echo "OK-the string is clean.";?>[/code] Link to comment https://forums.phpfreaks.com/topic/25745-regex-problem/#findComment-117580 Share on other sites More sharing options...
Nicklas Posted November 2, 2006 Share Posted November 2, 2006 [code]if (ctype_alnum($hash)) {echo "String Ok!";}[/code] Link to comment https://forums.phpfreaks.com/topic/25745-regex-problem/#findComment-118222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.