I am trying to validate a string (a name) using preg_match(). I am passing in a string called $lname which is a string containing an apostrophe which has been slashed. An example of this is "O\'Neill". I have tried multiple regex layouts and solutions for this including (\') , \' , and just '. It does not work and give a true output being valid. Can anyone offer a solution.
Here is my code:
$lname = "O\'Neill";
if(preg_match("/^[a-zA-Z\'\s-]+$/",$lname))
echo "valid";