I am making a registration/login form for my site but i came up with a problem... Trying to make the input strings from name and surname forms as cleaner as possible.I tried many premade functions to search strings and don't let users to use specials chars like @#$%^&*(){}" etc but when user is writing their name or surname in greek chars the without special chars, the function reads special chars.Below is the code:
$required_fields = array('name', 'surname', 'email', 'password', 'confirm_password');
$wrong_chars = "0123456789!@#$%^&*()+=-[]';,./{}|:<>?~";
foreach($required_fields as $field) {
if($_POST[$field] == '') {
$errors[] = "All Fields are required.";
break;
}
}
if(empty($errors)) {
if(strpbrk($name,$wrong_chars) !== false) {
$errors[] = "You can't use special characters on field: Name.";
}
else if(strpbrk($surname,$wrong_chars) !== false){
$errors[] = "You can't use special characters on field: Surame.";
}
}
Any help here and if there is any suggestion for a better algorithm would be appreciated.Thanks in advance.