So here is what I'm doing exactly:
I have a form with a caption on the right of it, I want to write in the form only A-Z,0-9 and whitespaces, and for the caption I want to do the opposite, so if the user write's something wrong I can show what's the problem for example: "Invalid Charachter"
But I'm stuck with +
and #
I want to ignore them too from the form with regular expression so I can show the "Invalid character"
message for these too, as I saw php thinks that + sign is = to space ( ) or what, but I need to ignore + and # signs too. This is my current code:
preg_match_all("/[^\w\s]/",$string,$matches);
foreach($matches[0] as $ic){
if(strpos($str,$ic) || $str[0] == $ic){
$fullname_error = "Invalid Character";
}
}
Valid strings:
- John Doe
- Mary Sue
Not valid strings:
- J#ohn Doe
- John&Doe
- John+Doe
- Mar@y+Sue
- !Mary Sue
- Mary Sue!