Avatar of Crazy Horse
Crazy Horse
Flag for South Africa

asked on 

How to validate names with apostrophes in them

I am trying to do simple php validation on a name field. But what I have now blocks everything except letters and spaces. What if the person has a ' in their name which isn't uncommon. e.g.: O'Brian

if (!preg_match("/^[a-zA-Z ]*$/",$_POST['name'])) {
  $error .= "Only letters and white space allowed"; 

Open in new window


Avatar of undefined
Last Comment
Dan Craciun

8/22/2022 - Mon