php - Allow whitespace, unicode letters, digits, underscore, dash AND comma? -


i'm pretty new @ subject preg , i'm using preg_match condition check if user has entered whitespace, unicode letters, digits, underscore or dash:

if(preg_match("/[^\040\pl\pn_-]/u", $term)) { 

but wanted allow comma. tried this:

if(preg_match("/[^\040\pl\pn,_-]/u", $term)) { 

and works , wanted know why. want understand better. why have ,_- , not -_, example allow comma?

i appreciate if explain me step step.

this because - used ranges in square brackets([] -> character classes). , manual: indicates character range, example: 0-9 or a-z.

so long put @ end you're fine , don't have escape it. in other cases have escape backslash e.g. \-.

means:

 ,_-  //at end _,-  //at end \-,_ //escape \-_, //escape ,\-_ //escape _\-- //escape 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -