Hi,
I am reading a database and i want to find if the field title contains only latin characters, numbers and any special character.
I know that regular expression must be used but i am not very good at reg exp.
Can anyone help.
Hi,
I am reading a database and i want to find if the field title contains only latin characters, numbers and any special character.
I know that regular expression must be used but i am not very good at reg exp.
Can anyone help.
This should get you started, it will match any alphanumeric characters and special characters !@#%&. and should be trivial to add any more special characters.
$field = "wtftest#$!@";
$numMatches = preg_match('/^[A-Za-z0-9!@#%$&.]+$/', $field, $matches);
if ($numMatches > 0) {
echo "Matches";
}
I'm not sure whether you want to find strings that "contain only latin characters" or "do not contain latin characters". If you want to find strings that don't contain Latin characters, mb_ereg_match may be of use (go to http://www.php.net/manual/en/function.mb-ereg-match.php). I've never used that function, though, so, in case this is what you need, I may not be able to help you any further.