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

Example Analysis of regular expression Registry Verification

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly shows you the "sample analysis of regular expression registry verification", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and learn the "regular expression registry verification example analysis" this article.

Regular expression

A regular expression is a logical formula for manipulating a string, that is, a "regular string" is formed by predefined specific characters and a combination of these specific characters. This "regular string" is used to express a filtering logic for a string.

Purpose of regular expression

1. Whether the given string conforms to the filtering logic of the regular expression (called "match")

two。 We can get the specific part we want from the string through regular expressions.

The characteristic of regular expressions is that

1. Very flexible, logical and functional

two。 Complex control of strings can be achieved quickly and in a very simple way.

3. For people who have just come into contact, it is more obscure.

Registry verification

1. Get id

Function $(id) {return document.getElementById (id);}

two。 Verify name

Function checkName () {/ / gets the value var username=$ ('user'). Value; / / determines that it cannot be empty if (username=='') {$('s1') [xss_clean] =' user name cannot be empty'; return false;} / / regular expression var reg=/ ^ [a-zA-Z] [a-zA-Z0-9] {4jue 9} $/ / / check whether the input matches the regular expression if (! reg.test (username)) {$('s1') [xss_clean] =' user name must be 5-10 digits or letters, and cannot start with a number' Return false;} / / match, return empty $('s1') [xss_clean] ='; return true;}

Remarks: S1 is added after the input box to judge the content of the prompt

3. Verify password

Function checkPwd () {/ / get the same value as above. / / judgment cannot be empty ditto. / / regular expression var reg=/ ^\ S {6,} $/; / / detects whether the input matches the regular expression if (reg.test (password) = = false) {$('s2') [xss_clean] =' password must be more than 6 digits'; return false;} / / matches and returns empty ditto. }

4. Verify mailbox

Function checkEmail () {/ / get the same value as above. / / judgment cannot be empty ditto. / / regular expression var reg=/ ^\ walled @\ wt +\ .com | cn | net$/; / / check whether the input matches the regular expression if (! reg.test (email)) {$('s3') [xss_clean] =' invalid mailbox'; return false;} / / match, return empty ditto … }

5. Verify the mobile phone number

Function checkTel () {/ / get the same value as above. / / judgment cannot be empty ditto. / / regular expression var reg=/ ^ 1 [34578]\ d {9} $/; / / detect whether the input matches the regular expression if (! reg.test (tel)) {$('s4') [xss_clean] =' invalid mobile phone number'; return false;} / / match, return empty ditto … }

6. Verify ID number

Function checkCid () {/ / get the same value as above. / / judgment cannot be empty ditto. / / regular expression var reg=/ ^\ d {15} $| ^\ d {17}\ d | xtriple; / / check whether the input matches the regular expression if (! reg.test (cid)) {$('s5') [xss_clean] =' illegal ID card'; return false;} / / match, return empty ditto … }

7. Verify the QQ number

Function checkQQ () {/ / get the same value as above. / / judgment cannot be empty ditto. / / regular expression var reg=/ ^ [1-9]\ d {7 reg.test 10} $/; / / detect whether the input matches the regular expression if (! reg.test (qq)) {$('s6') [xss_clean] =' regular expression must be composed of 8 to 11 digits and must not start with zero; return false;} / / match, return empty ditto … }

8. Test all conditions

Function checkAll () {if (checkName () & & checkPwd () & & checkEmail () & & checkTel () & & checkCid () & & checkQQ ()) {return true;} else {return false;}}

Of course, you can use the jQuery Validate verification framework for expression verification later, which is more convenient.

The above is all the contents of the article "sample Analysis of regular expression Registry validation". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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