Hello everyone! I need some help with regular expressions. I'm using preg_match to validate name field for a form. I need to allow only alphabets and spaces. I'm unable to get it working for spaces. Please suggest me some code. Here is what i'm doing. if(!preg_match('[a-zA-Z\s]', $name))... Thanks
Right now you're letting in just a single character, you need to wrap your expression in () and add + after the [] which means 1 or more. This should work: ([a-zA-Z\s]+)
Thanks. But it's now letting everything pass through. Including numbers, special characters etc.. :-(
Note the space after the second Z, thats all you have to do. "/^[a-zA-Z ]+$/" PHP: ..and this one indicates the first letter needs to be a Capital letter, which names should be I guess. "/^[A-Z][a-zA-Z ]+$/" PHP: