houssam_ballout Posted May 2, 2011 Share Posted May 2, 2011 Hello, I had this code that checks for a form validity using AJAX: ereg("^[a-zA-Z0-9]+$ This will check only for a-z,0-9 and A-Z, how can I allow white spaces to be inserted? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/235327-help-adding-ajax-validate/ Share on other sites More sharing options...
spiderwell Posted May 2, 2011 Share Posted May 2, 2011 preg_match ("/^[A-Za-z0-9\ ]+$/", $theinput ); Quote Link to comment https://forums.phpfreaks.com/topic/235327-help-adding-ajax-validate/#findComment-1209319 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 spiderwell's solution will get you the space character. Often this is what people really want, but if you indeed want "whitespace" that includes tabs and newlines, then add "\s" character class instead. "/^[A-Za-z0-9\s]+$/" Quote Link to comment https://forums.phpfreaks.com/topic/235327-help-adding-ajax-validate/#findComment-1209770 Share on other sites More sharing options...
spiderwell Posted May 3, 2011 Share Posted May 3, 2011 true fact & possible future siggie: "Anything I can do, gizmola can do better" Quote Link to comment https://forums.phpfreaks.com/topic/235327-help-adding-ajax-validate/#findComment-1209806 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 true fact & possible future siggie: "Anything I can do, gizmola can do better" Not at all, he probably wanted to do what you originally suggested, so all i could offer was a caveat. Quote Link to comment https://forums.phpfreaks.com/topic/235327-help-adding-ajax-validate/#findComment-1210007 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.