robcrozier Posted October 18, 2007 Share Posted October 18, 2007 Hi all, i'm pretty new to the preg_match() function and what im simply trying to do it find out if a string contains only letters and numbers, nothing else! Here is what i have so far, tough it does not work: if (preg_match('/^[a-zA-Z0-9]+$/', $catagory)) { //OK } else { // NOT OK } Nay help would be appreciated, cheers! Quote Link to comment https://forums.phpfreaks.com/topic/73863-solved-preg_match-help/ Share on other sites More sharing options...
robcrozier Posted October 18, 2007 Author Share Posted October 18, 2007 solved: (eregi("^[[:alnum:] ]{1,}$", $var)) Quote Link to comment https://forums.phpfreaks.com/topic/73863-solved-preg_match-help/#findComment-372661 Share on other sites More sharing options...
MadTechie Posted October 18, 2007 Share Posted October 18, 2007 this works okay.. infact the only differents from your failed one to your working one is the working allows spaces! <?php if (preg_match('/^[a-z0-9 ]+$/i', $catagory)) { //OK } else { //Not OK } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73863-solved-preg_match-help/#findComment-372667 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.