search

Home  >  Q&A  >  body text

How to write a regex in php to verify email and mobile phone number at the same time?

php verifies email and mobile phone number at the same time

Need a regular expression that can match both mobile phone numbers and email accounts

習慣沉默習慣沉默2748 days ago703

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人2017-05-16 13:08:44

    First use /^[0-9]*$/ to determine whether it is a pure number. If it is, enter the logic of mobile phone number verification. Use /^1[3|4|5|7|8]d{9}$ / to verify whether it is a legal mobile phone number.

    If it is not a pure number, enter the logic of email verification. /^w+((-w+)|(.w+))@[A-Za-z0-9]+((.|-)[A-Za- z0-9]+).[A-Za-z0-9]+$/ can be used to verify email

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:08:44

    Use this to verify the email address, and then when it returns false, use the regular pattern to verify the mobile phone number, like this.
    $email = 'fengdingbo@gmail.com';
    $result = filter_var($email, FILTER_VALIDATE_EMAIL);
    var_dump($result); // string(20) "fengdingbo@gmail.com"

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:08:44

    It’s a bit loose to verify email and mobile phone number at the same time. You can take a look at the example below

    reply
    0
  • Cancelreply