I've always struggled with RegEx so forgive me if this may seem like an awful approach at tackling my problem.
When users are entering first and last names I started off just using the basic, check for upper and lower case, white space, apostrophes and hyphens
if (!preg_match("/^[a-zA-Zs'-]+$/", $name)) { // Error }
Now I realise this isn't the best since people could have things such as: Dr. Martin Luther King, Jr. (with comma's and fullstops). So I assume by changing it to this would make it slightly more effective.
if (!preg_match("/^[a-zA-Zs,.'-]+$/", $name)) { // Error }
I then saw a girls name I know on my Facebook who writes her name as Sian, which got me thinking of names which contain umlauts as well as say Japanese/Chinese/Korean/Russian characters too. So I started searching and found ways by writing each of these characters in there like so.
if (!preg_match("/^[a-zA-Zsàáa???èéê?ìí??òó????ùú?ü?y?????àá????èéê?ìí??òó????ùú?ü?Y?????????e ,.'-]+$/u", $first_name)) { // Error }
As you can imagine, it's extremely long winded and I'm pretty certain there is a much simpler RegEx which can achieve this. Like I've said, I've searched around but this is the best I can do.
So, what is a good way to check for upper and lower case characters, commas, full stops, apostrophes, hypens, umlauts, Latin, Japanese/Russian etc
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…