Cod-nes Posted July 19, 2010 Share Posted July 19, 2010 How can I validate input from a form that only allows numbers and letters in php? Link to comment Share on other sites More sharing options...
MrFish Posted July 19, 2010 Share Posted July 19, 2010 I love this website-http://tinyurl.com/38jwgtnCheck the first link. Link to comment Share on other sites More sharing options...
wirehopper Posted July 19, 2010 Share Posted July 19, 2010 $bValid=preg_match('/^[0-9a-z]+$/i',$sString); Link to comment Share on other sites More sharing options...
End User Posted July 19, 2010 Share Posted July 19, 2010 One minor change to allow upper-case letters:$bValid=preg_match('/^[0-9a-zA-Z]+$/i',$sString); Link to comment Share on other sites More sharing options...
Cod-nes Posted July 19, 2010 Author Share Posted July 19, 2010 Thanks. It looks like it works. =D By the way, what does the + do? Also where would I put in this: {4,12}? (I forgot to add it.) Link to comment Share on other sites More sharing options...
23.12.2012 Posted July 19, 2010 Share Posted July 19, 2010 What's wrong with ctype_alnum()? Link to comment Share on other sites More sharing options...
Synook Posted July 19, 2010 Share Posted July 19, 2010 One minor change to allow upper-case letters:$bValid=preg_match('/^[0-9a-zA-Z]+$/i',$sString);The i modifier means case-insensitive. Link to comment Share on other sites More sharing options...
wirehopper Posted July 19, 2010 Share Posted July 19, 2010 What's wrong with ctype_alnum()?Good point - easier and almost certainly executes faster than preg.Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.