How can I add/improvised my code so Spanish accent will be considered as valid in addition to normal alphabet (a-z)
I have the following in my code
public static function IsAlpha($s){
$reg = "#[^a-z\s-]#i";
$count = preg_match($reg, $s, $matches);
return $count == 0;
}
As found in the answer to this question, you could match accented characters using the full Letter Unicode property
\p{L}. That includes regulara-zcharacters along with accented ones, so replacea-zin your expression with this like so:Note that to use this you need the UTF-8 modifier
uafter your closing delimiter, as the docs say such Unicode “character types are available when UTF-8 mode is selected“.