Mobile number check pattern in PHP

I can not write the exact template for a 10-digit mobile number (like 1234567890 format) in PHP. Email authentication works.

here is the code:

function validate_email($email)
{
return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]    {2,6}$", $email);
}

function validate_mobile($mobile)
{
  return eregi("/^[0-9]*$/", $mobile);
}
+4
source share
1 answer

Check Mobile Number

You can preg_match()check the 10-digit mobile numbers:

preg_match('/^[0-9]{10}+$/', $mobile)

To call it in a function:

function validate_mobile($mobile)
{
    return preg_match('/^[0-9]{10}+$/', $mobile);
}

Email Verification

You can use filter_var()with FILTER_VALIDATE_EMAILto check your email:

$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $emailErr = "Invalid email format"; 
}

To call it in a function:

function validate_email($email)
{
    return filter_var($email, FILTER_VALIDATE_EMAIL);
}

However, it filter_varwill return the filtered value on success and falseon failure.

Additional information at http://www.w3schools.com/php/php_form_url_email.asp .

, preg_match() , :

preg_match('/^[A-z0-9_\-]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z.]{2,4}$/', $email)
+7

All Articles