5ury4 Posted March 26, 2007 Share Posted March 26, 2007 Hello everyone! I need simple help with the syntax of preg_match, what I'm trying to do is to see if the user inputs any special character that is -> "@#$%^&*()+=-[]\\\';,./{}|\" How should I preg_match this with a given variable say $userinput ? I tried this code, but the problem with it was though it deteced # and $ but it refused to detect ! and @. <? $userinput = "test"; if(preg_match("/\!\@\#\$\%\[\]/",$userinput)){ echo "Special Characters Found"; } else{ echo "No SPeical character found."; } ?> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/44365-solved-preg_match-help-needed/ Share on other sites More sharing options...
ted_chou12 Posted March 26, 2007 Share Posted March 26, 2007 rather than including each special characters, wont it be easier to just include what you want, so the alphbets and numbers? if(!eregi("^([a-z0-9])*$",$lname)) {echo "invalid found!";} Link to comment https://forums.phpfreaks.com/topic/44365-solved-preg_match-help-needed/#findComment-215475 Share on other sites More sharing options...
5ury4 Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks a lot that worked Link to comment https://forums.phpfreaks.com/topic/44365-solved-preg_match-help-needed/#findComment-215477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.