Jump to content

Noob Regex Issue


Drongo_III

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/269409-noob-regex-issue/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/269409-noob-regex-issue/#findComment-1385671
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.