How can I perform alphanumeric with regex space model validation in CakePHP?
I have a user registration form and I want the user to enter their first and last name (i.e. Donalg Doonsberry). If the user does not provide their name in this way, entry will be rejected. I figured something like this would work for my regex user validation in cakephp:
'name'=>array('Name has to be comprised of letters.
'=>array('rule'=>array('custom', '/[A-Za-z ]+/')
)),
0
a source to share
3 answers
You have to be careful when checking names ... how about:
- Donalg McDonald <- capital in the middle of the word
- Donalg Fooble-Whiffery> - portable
- Donalg Dénnsbnérry-McDonald Sr. 3rd - you get the idea
To check names in the specified format:
/[A-Z][a-z]+ [A-Z][a-z]+/
Be a little softer:
/([\w.-]+ )+[\w+.-]/
+6
a source to share