php preg_match

Associate
Joined
19 Jul 2006
Posts
1,847
I have the following code that checks to see that the email is correct.

How do i alter the phone one to check that it contains at least 9 numbers?

PHP:
//Check to make sure sure that a valid email address is submitted
		if(trim($_POST['email']) === '')  {
			$hasError = true;
		} else if (!preg_match('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$^', trim($_POST['email']))) {
			$hasError = true;
			$errorMessage = "Please enter a valid email address!";
		} else {
			$email = trim($_POST['email']);
		}

		//phone
		if(isset($_POST['phone'])) $phone = trim($_POST['phone']);

TIA
 
Just checked that site which is good but im now unsure of the {} on the site is says
{9} means exactly 9

Now in the code above {9} seams to work with 9 or above?
 
Back
Top Bottom