简体   繁体   中英

Lithuanian phone number validation

We have 2 styles of phone numbers:

86 *** ****

+3706 *** ****

*** **** - random numbers

I used this before but now I need to validate both formats.

static function isPhoneNumber($phoneNumber) {
    return preg_match('/^[+0-9. ()-]*$/ui', $phoneNumber);
}

How to validate these two numbers using regex?

Regex:

(86|\+3706) \d{3} \d{4}
  • (86|\\+3706) looks for either 86 or +3706
  • \\d{3} and \\d{4} look for 3 and 4 digits respectively

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM