Drongo_III Posted October 13, 2012 Share Posted October 13, 2012 Hi Guys Bit stuck on this. I have a textarea and as part of validating it I want to run a regex to ensure it matches my criteria. The problem is everytime I introduce a literal fullstop the check fails - even though it should be one of the acceptable characters. The regex is as follows: $pattern3 = '/^[a-zA-Z0-9"\'\.]{3,}$/'; if(!preg_match($pattern3, $posts['message'])){ $errorsArray[] = 'Please provide a short description of your problem.'; } Anyone point me in the right direction please? Quote Link to comment https://forums.phpfreaks.com/topic/269409-noob-regex-issue/ Share on other sites More sharing options...
requinix Posted October 13, 2012 Share Posted October 13, 2012 Looks fine to me, though the backslash isn't necessary when the period is in a character set (loses its metacharacter meaning). What message text is failing? Quote Link to comment https://forums.phpfreaks.com/topic/269409-noob-regex-issue/#findComment-1384911 Share on other sites More sharing options...
.josh Posted October 16, 2012 Share Posted October 16, 2012 my random shot in the dark is maybe you are trying to enter text on multiple lines (IOW pressing enter in the msg at some point in time) so it's failing because of \n or \r\n chars Quote Link to comment https://forums.phpfreaks.com/topic/269409-noob-regex-issue/#findComment-1385586 Share on other sites More sharing options...
ManiacDan Posted October 16, 2012 Share Posted October 16, 2012 Add an s after the final slash to allow multiple lines. Quote Link to comment https://forums.phpfreaks.com/topic/269409-noob-regex-issue/#findComment-1385598 Share on other sites More sharing options...
.josh Posted October 16, 2012 Share Posted October 16, 2012 Add an s after the final slash to allow multiple lines. Nah, the s modifier will allow the dot (as a metachar, not as a literal char inside the char class he has) to also match newline chars, but he is not using a dot in his pattern, he is using a character class, so the s modifier won't actually work. Assuming my shot in the dark is right, he needs to throw newline chars into the mix, and since he'd specifically be matching for them (either putting them in a char class or listing them as an alternation to the char class), s modifier wouldn't be applicable. Quote Link to comment https://forums.phpfreaks.com/topic/269409-noob-regex-issue/#findComment-1385671 Share on other sites More sharing options...
ManiacDan Posted October 17, 2012 Share Posted October 17, 2012 You're correct, I was thinking there was a bare dot in the pattern. Congrats, btw. Quote Link to comment https://forums.phpfreaks.com/topic/269409-noob-regex-issue/#findComment-1385697 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.