So I have this assignment. I have to validate a name input that can contain big and small letters, apostrophe, spaces or comas. So I've come up with this for validation:
$name = $_POST['your_name'];
$regex_name = '/([A-Z]|[a-z])([A-Z][a-z\s])+/';
if (!preg_match($regex_name, $name)) {
echo '<span style="color:red">Please input a valid name!</span><br />';
}
But it doesn't seem to work fine and I don't know why.
I've read about regex and the rules but I don't get what I'm doing wrong. I've even seen some examples here on stackoverflow but it's still not clear for me.
I think this should validate at least letters but it gives false even for a simple input as 'error'.
Please help!
