Code: Select all
public static function hasSpecialCharacters($string) {
// checking for special characters
$specialChars = array('!', '\@', '#', '\\\\', '/', '\^', '\+',
'\(', '\)', '\[', '\]', '\.', ',', '\$', '\?',
'<', '>', '{', '}', '\|', '-', '=', '~', '\`' );
$regex ='/[';
$last = end($specialChars);
foreach($specialChars as $char) {
$regex .= $char;
if($char != $last)
$regex .= '|';
}
$regex .=']/';
if(preg_match($regex, $string)) {
return true;
}
return false;
}Code: Select all
/[!|\@|#|\\|/|\^|\+|\(|\)|\[|\]|\.|,|\$|\?|<|>|{|}|\||-|=|~|\`]/