Im validating a form and its easy to validate numbers, letters a-z and so on but when i got to the point where i need to validate a field which must contain only the characters (a-z and special characters such as öçğüiş) with at least one space only I am really stuck!
I tried the following and some other techniques without success:
function validateAlphaSpecial($value) {
if (ereg("/^[\p{L}\s]+$/", $value, $regs)) {
echo 'true';
} else {
echo 'false';
}
}
Has anyone got a solution for this. Thank you.
Ereg has been deprecated as of PHP 5.3.0 like others said and you shouldn't use EREG.
The snippet below fits your validating requirement: a-z and special characters such as öçğüiş with at least ONE SPACE.
if( preg_match("/[\p{L}]\s{1,}+/u", $value) > 0 ) {
echo 'Valid';
} else {
echo 'Not valid';
}
About /u modifier [ from documentation ] :
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8.