In JS I used this code:
if(string.match(/[^A-Za-z0-9]+/))
but I don\'t know, how to do it in PHP.
PHP can compare a string to a regular expression using preg_match(regex, string)
like this:
if (!preg_match('/[^A-Za-z0-9]+/', $string)) {
// $string contains only English letters and digits
}
if (preg_match('/^[\w\s?]+$/si', $string)) {
// input text is just English or Numeric or space
}
Have a look at this shortcut
if(!preg_match('/[^\W_ ] /',$string)) {
}
the class [^\W_]
matches any letter or digit but not underscore . And note the !
symbol . It will save you from scanning entire user input .