I have a php script which I need to validate several inputs with.
Is there any reliable and very good regular expression to check against when it comes to telephone nr, name and email adress validation?
Could somebody please supply these as I am very novice in regexp?
What I want is for example:
Telephone Nr: all number allowed, must be atleast 6 numbers, max 12 numbers, ‘+’ sign allowed, space allowed, ‘-‘ sign allowed, as well as other things I haven’t thought about yet.
Name: No numbers allowed, only characters in both lower and uppercase. Also the three swedish chars ‘Å, Ä, Ö’ in both lower and uppercase, also space, ‘-‘ sign allowed, and all others I havent thought about.
Email: Email adress is pretty standard over the world, so I don’t know exactly what to ask for here, but you probably know what I want.
Thanks for all help
As Andrew White said, emails shouldn’t be validated [only] by regex, but you can check out this one:
it’s closest to the email address spec I’ve ever found (no tests have been found which it fails)… can’t remember where it’s from, will edit my answer as soon as I find it again
[EDIT]
Found it, definitely worth a read: http://fightingforalostcause.net/misc/2006/compare-email-regex.php
[EDIT]
This should do for the phone numbers:
Similar can be done for the names, but don’t forget the case-insensetive flag (i.e.
'{pattern}i', there are also some good regex cheat sheets out there, for example this one from addedbytes.com: http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/