does anyone know of any good resources for php regex for form validation.

I am looking for good regex for

name: (including -.' and no spaces in the first space no doubles of ..''--

phone: again no spaces at the start allowing + and -

alpha: only lowercase letters no numbers no spaces allowing -_ but no doubles --__ or _-_-
alphaspace: same as above but with spaces allowing .',-_ but no double ..''--__
alphanumeric: same as alpha but with numbers
alphanumericspace: same as alphaspace but with numbers
date: dd-mm-yyyy
years: numeric maxiumum 2 numbers no spaces

i have been through 100 sites today only to find error after error

i found this one for email seems to work

$emailx ="/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$/";
7 Years
Discussion Span
Last Post by shadiadiph

Also if you want to learn the regex syntax the good old way then you can find the official documentation of the syntax at http://au2.php.net/manual/en/regexp.reference.php
You will find that the easiest way to learn is by starting with simple regex commands such as modifying existing ones then working you way up the scale untill you can memorize what everything does.

Also as for the regex validation you have requestion, the following may do the job:

if (pregmatch('/((*[ ]*|*\-\-*)?[ ](*[ ]*|*\-\-*)|(*[ ]*|*\-\-*)[ ](*[ ]*|*\-\-*)?)/i',$data)) {
//error found as name contains double dash or more than one space

if (pregmatch('/[^0-9]/i',$data)) {
//error found as it contains non-number characters

I thought I would share a joke from phpfreaks forums:
If preg was a women I would the pattern and she would replace me with $1.
Thats preg_replace right.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.