Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use regular expressions to verify account and Mobile number in Javascript

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to use regular expressions to verify your account and mobile phone number in Javascript. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Verify whether the account is legal

Verification rules: letters, numbers, underscores, the beginning of the letter, 4-16 digits.

Function checkUser (str) {var re = / ^ [a-zA-z]\ w {3 re.test 15} $/; if (re.test (str)) {alert ("correct");} else {alert ("error");}} checkUser ("neirong.org"); / / call

2. Mobile phone number

Validation rule: 11 digits, starting with 1.

Function checkMobile (str) {var re = / ^ 1\ d {10} $/ if (re.test (str)) {alert ("correct");} else {alert ("error");}} checkMobile ('13800138000'); / / call

3. Telephone number

Verification rules: area code + number, area code begins with 0, 3 or 4 digits, the number consists of 7 or 8 digits, there can be no connector between the area code and the number, or "-" connection

Function checkPhone (str) {var re = / ^ 0\ d {2 3} -?\ d {7 8} $/; if (re.test (str)) {alert ("correct");} else {alert ("error");} checkPhone ("09557777777"); / / call

4. Mailbox

Verification rules: let's divide the email address into "part one @ part two". The first part: by letters, numbers, underscores, short lines "-", periods. " The second part: for a domain name, the domain name is composed of letters, numbers, short-term "-" and domain name suffixes, and the domain name suffixes are generally .xxx or .xxx.xx. The domain name suffixes of Zone 1 are generally 2-4 digits, such as cn, com and net. Now some domain names are larger than 4 digits.

Function checkEmail (str) {var re = / ^ (\ wmurf *\. *) + @ (\ wmurf?) + (\. W {2,}) + $/ if (re.test (str)) {alert ("correct");} else {alert ("error");} checkEmail ("contact@cnblogs.com") / / calling the above is how to use regular expressions to verify your account and mobile phone number in Javascript. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report