Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
computers:php_regex_validation [2009/02/13 09:51]
daniel
computers:php_regex_validation [2015/03/24 05:42] (current)
Line 6: Line 6:
 <code php> <code php>
 /** /**
- * Match alphnumeric ​and underscore username+ * Match alphanumeric ​and underscore username
  * 3-16 characters long  * 3-16 characters long
  */  */
Line 15: Line 15:
 </​code>​ </​code>​
  
 +
 +===== Remove Non-Alphanumeric Characters =====
 +Reference: http://​www.phpro.org/​examples/​Strip-All-Non-Alphanumeric-Characters-Except-Space-With-PHP.html
 +
 +<code php>
 +/**
 +* Remove all non alpha numeric characters except a space
 +* @param ​   string ​   $string The string to cleanse
 +* @return ​   string
 +*/
 +function alphanumericAndSpace( $string ) {
 + return preg_replace('/​[^a-zA-Z0-9\s]/',​ '',​ $string);
 +}
 +</​code>​