Reputation: 85
I am developing a web application for a french client. Now am really confused about the french character validation in PHP and Javascript too.
I would like to allow alphanumeric and special characters : é è ê î ï ô à ç , . #.
This is the PHP code I am using for alphanumeric and normal character validation
$aValid = array(' ', ' ',' ',' ',' ','-','.',',','#');
if(!ctype_alnum(str_replace($aValid, '', $str))) {
return false;
}
else
return true;
Please help me to include the validation of special characters : é è ê î ï ô à ç , . # in this code. I am also confused about the validation in javascript too. It is UTF-8 encoded so can I directly use the special characters in it?
Thanks in advance,
Upvotes: 0
Views: 979
Reputation: 3684
I would use regular expressions for such tasks:
return preg_match("/^[a-z\déèêîïôàç,.#]+$/ui", $str);
Upvotes: 3