PHP Regex Unknown Modifier -


read ton, didn't see answer. sorry if duplicate.

running php 5.4.

i have form takes contact info (name, email, number, etc).

the regex is: allow letters, numbers, space, dash, backslash, colon, @ sign, , forward slash.

this i'm using (for input values, showing 1 below):

if (!preg_match("/^[./\\@\w\sa-za-z0-9:-]+$/", $_post["name"]) 

i keep getting unknown modifier error. don't care if above fixed, or replaced different regex, need allow things mentioned earlier.

thanks in advance.

you need escape /

this should be

^[.\/\\@\w\sa-za-z0-9-]+$ 

test regex pattern @ regex101


  • \s match white space character [\r\n\t\f ] if looking space use

  • \w match word character [a-za-z0-9_] includes underscore well. remove regex pattern


only allow letters, numbers, space, dash, backslash, colon, @ sign, , forward slash.

it should ^[0-9a-za-z \\:@\/-]+$

note: make sure hyphen - must in beginning or ending of character class or should escaped because hyphen has special meaning in character class define range.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -