sid0972 Posted February 9, 2013 Share Posted February 9, 2013 following is the regex to match several words,letters and spaces, but it seems i got it wrong. $expr='/^[a-zA-Z0-9 ]*{2,36}$/'; if(preg_match($expr,$input)) { echo "good "; } else { echo "not good"; } can anyone tell me Whats wrong? Quote Link to comment https://forums.phpfreaks.com/topic/274268-regex-not-working/ Share on other sites More sharing options...
sid0972 Posted February 9, 2013 Author Share Posted February 9, 2013 nevermind i found it. function check_system($input) { $expr = '/^[0-9a-zA-Z ]+$/'; if(preg_match($expr,$input)) { return true; } else { return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/274268-regex-not-working/#findComment-1411373 Share on other sites More sharing options...
Christian F. Posted February 10, 2013 Share Posted February 10, 2013 To those who're wondering: The problem was that you had used two quantifiers. Both * (zero, or many) and {2,36} (between 2 and 36, inclusive). Quote Link to comment https://forums.phpfreaks.com/topic/274268-regex-not-working/#findComment-1411438 Share on other sites More sharing options...
sid0972 Posted February 10, 2013 Author Share Posted February 10, 2013 oh ok is there any way i can tell if there's a problem with a regex, or i just have to look at it? Quote Link to comment https://forums.phpfreaks.com/topic/274268-regex-not-working/#findComment-1411531 Share on other sites More sharing options...
Christian F. Posted February 10, 2013 Share Posted February 10, 2013 If the RegExp doesn't work as intended, then there's a problem with it. Especially if it spits out an error message. There are also tools that validate regular expressions, but you have to be careful with what dialect they validate for. Other than that, there's no other way than to look at it and (trying to) understand what it does. Quote Link to comment https://forums.phpfreaks.com/topic/274268-regex-not-working/#findComment-1411536 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.