regex - Check for multiple and combination patterns with PHP preg_match -


I do not want to allow multiple patterns in a string, like

  $ string = "Php in stack overflow"; // Multiple locations are not allowed $ string = "php in - stackoverflow"; // Multiple Hyphen $ string = "php in__stackoverflow" is not allowed; // multiple underscores are not allowed etc.   

So, it works with these lines,

  if (preg_match ('/ \ s \ S + / ', $ string)) "Only one single location is allowed"; If (preg_match ('/ \ - \ - + /', $ string)) "only one hyphen is allowed" echo; If (preg_match ('/ \ _ \ _ + /', $ string)) "Only one single underscore is allowed";   

I do not want to allow the pattern of the combinations given below and the above lines do not work,

  $ string = "php in -stackoverflow "; // One location with a hyphen is not allowed $ string = "php in-_stackoverflow"; // An underscore hyphen is not allowed $ string = "php in_stackoverflow";   

Any ideas I can get it with a simple script?

This is the same class class, which matches multiple characters. If only (preg_match ('/ [\ s -_] [\ s-_] + /', $ String)) "Only one place, hyphen or underscores are permitted"

  ;    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -