Jump to content

Name Validation Special Characters With Preg_match()


Tyson86

Recommended Posts

Hey guys, I am new on this forum but have lurked around in the past and have learned many things, so first of all I just wanted to say a huge thank you to all those who help out and share their knowledge... it's greatly appreciated.Anyway, as for my question, I want to make sure a user inputs valid name into a form. Essentially just letters, spaces, hyphens, periods, and apostrophes would be valid characters. So my first function looked like this:if(!preg_match("#^[-A-Za-z' .]*$#",$string)){ $isValid = false;Which worked fine, however I realized special characters like "é" "è" "ê" such as in the city of Québec are invalid, which I need to allow. The code for the character "é" is & # 2 3 3 ; (without the spaces) so i changed my function to:if(!preg_match("#^[-A-Za-z\&\#0-9\;' .]*$#",$string)){ $isValid = false;This caused some problems, not to mention it allowed the user to enter characters #,&,; and numbers 0-9 for a name, which I do not what. I'm not too comfortable with the preg_match() function and I have no idea how to allow the special characters. Any ideas?Oh and also am I forgetting any characters that could be found in a name? I would of course also like to include the other special characters associated with letters a,i,o,u etc..Thanks for any help

Link to comment
Share on other sites

Does your document charset allow these characters as literals? Might be something to consider.

Link to comment
Share on other sites

What's the actual pattern you're trying to use? The main thing it looks like you're having problems with is that you chose a pattern delimiter that you're trying to use in the pattern. You can't use delimiters in the pattern, so choose another delimiter character.if(!preg_match("#^[-A-Za-z\&\#0-9\;' .]*$#",$string)){

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...