Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Js Mobile phone number Verification regular expression correct Writing

Shulou Source: shulou.com Published: 2022-06-02 04:36:13 10月03日 Update

This article mainly explains the "js mobile phone number verification regular expression correct writing", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "js mobile phone number verification regular expression correct writing"!

Write a simple regular expression to verify 11-digit mobile phone numbers, starting with 13, 15, 18. I started by writing:

Var reg = / ^ (13 [0-9] {9}) | (15 [0-9] {9}) | (18 [0-9] {9}) $/

It is found that even 13988888877157777 can pass the verification, which indicates that the writing is wrong. This is what I intended:

^ (13 [0-9] {9}) $or ^ (15 [0-9] {9}) $or ^ (18 [0-9] {9}) $

So the correct way to write it is: var reg = / ^ 1 [358] [0-9] {9} $/; only in this way can 11 digits be guaranteed.

Thank you for your reading, the above is the content of "js mobile phone number verification regular expression correct writing". After the study of this article, I believe you have a deeper understanding of the problem of correct writing of js mobile phone number verification regular expression, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Writing verification number mobile phone regular expression learning content that is the beginning ideas situations numbers articles more original intention knowledge knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info Apple vpn Shulou Technology