In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 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 "js regular expression verification example analysis", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "js regular expression verification example analysis" this article.
The following functions are called:
Function check () {var bb = document.getElementById ("txt_id"). Value;//txt_id is the ID alert (ismobile (bb)) of the text box; / / ismobile represents any of the following function names}
HTML Code:
= 48&&keycode & /'|
Regular expression [^ & / |'\] +
Date verification
Matching forms such as: 20030718pr 030718
Scope: 1900 Murray 2099
Regular expression (19) {1} | (20) {1}) d {2}) | d {2}) [01] {1} d {1} [0-3] {1} d {1}
Regular expressions that match Chinese characters: [\ u4e00 -\ u9fa5]
Note: matching Chinese is really a headache. It's easy to have this expression.
Match double-byte characters (including Chinese characters): [^\ X00 -\ xff]
Note: can be used to calculate the length of a string (a double-byte character length meter 2 ~ ~ ASCII character counter 1)
A regular expression that matches a blank line:\ n\ s*\ r
Comment: can be used to delete blank lines
A regular expression that matches the HTML tag:
< (\S*?)[^>] * >. *? |
< .*? />Commentary: the version circulated on the Internet is too bad, the above one can only match part of it, and there is still nothing I can do about complex nested tags.
Regular expression that matches the leading and trailing white space characters: ^\ s* |\ sblank $
Comment: a very useful expression that can be used to delete white space characters (including spaces, tabs, page feeds, etc.) at the beginning and end of a line
The regular expression that matches the Email address:\ W + ([- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) *
Comment: form validation is very useful
Regular expression that matches the URL URL: [a-zA-z] +: / / [^\ s] *
Note: the function of the version circulated on the Internet is very limited, and the above version can basically meet the needs.
Whether the matching account is legal (5-16 bytes are allowed at the beginning of the letter, and alphanumeric underscores are allowed): ^ [a-zA-Z] [a-zA-Z0-9 _] {4j 15} $
Comment: form validation is very useful
Match domestic phone number:\ d {3} -\ d {8} |\ d {4} -\ d {7}
Commentary: matching forms such as 0511-4405222 or 021-87888822
Match Tencent QQ number: [1-9] [0-9] {4,}
Commentary: Tencent QQ starts from 10000
Match the postcode of China: [1-9]\ d {5} (?!\ d)
Commentary: the postal code of China is 6 digits
Match ID:\ d {15} |\ d {18}
Commentary: Chinese ID cards are 15 or 18 digits
Match ip address:\ d +\.\ d +\.\ d +
Note: useful when extracting ip addresses
Extract the ip address from the information:
(\ d+)\. (\ d+)
Extract the Chinese mobile phone number from the information:
(86) * 013\ d {9}
The Chinese fixed telephone number extracted from the information:
(\ (\ d {3pr 4}\) |\ d {3pr 4}-|\ s)?\ d {8}
Chinese phone numbers (including mobile and landline phones) in the extracted information:
(\ (\ d {3pr 4}\) |\ d {3pr 4}-|\ s)?\ d {7pr 14}
The postcode of China in the extracted information:
[1-9] {1} (\ d +) {5}
The Chinese ID card number extracted from the information:
\ d {18} |\ d {15}
Extract integers from the information:
\ d +
Extract the floating point number (that is, decimal) in the information:
(-?\ d *)\. D +
Extract any number from the information:
(-?\ d *) (\.\ d +)?
Extract the Chinese string in the information:
[\ u4e00 -\ u9fa5] *
Extract a double-byte string (Chinese character) from the information:
[^\ X00 -\ xff] *
Extract the English string from the information:
\ w *
Extract web links from the information:
(h | H) (r | R) (e | E) (f | F) * = * ('| ")? (\ w |\.) + ('|" | * | >)?
The email address in the extracted information:
\ w + ([- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) *
Extract the picture link in the information:
(s | S) (r | R) (c | C) * = * ('| ")? (\ w |\ |\ /) + ('|" | * | >)?
Match specific numbers:
^ [1-9]\ positive integer matching $/ /
^-[1-9]\ negative integer matching $/ /
^ -? [1-9]\ match integer
^ [1-9]\ d* | 0 $/ / matches a non-negative integer (positive integer + 0)
^-[1-9]\ d* | 0 $/ / matches non-positive integers (negative integers + 0)
^ [1-9]\ d *\.\ d * | 0\.\ d * [1-9]\ dfloat $/ / matches positive floating point numbers
^-([1-9]\ d *.\ d * | 0.\ d * [1-9]\ d *) $/ / matches negative floating point numbers
^ -? ([1-9]\ d *.\ d * | 0\.\ d * [1-9]\ d * | 0?\ .0 + | 0) $/ / match floating point number
^ [1-9]\ d *.\ d * | 0\.\ d * [1-9]\ d * | 0?\ .0 + | 0 $/ / matches non-negative floating point numbers (positive floating point number + 0)
^ (- ([1-9]\ d *\.\ d * | 0\.\ d * [1-9]\ d *)) | 0?\ .0 + | 0 $/ / matches non-positive floating point numbers (negative floating point + 0)
Commentary: useful when dealing with a large amount of data, pay attention to corrections in specific applications
Match a specific string:
^ [A-Za-z] + $/ / matches a string of 26 English letters
^ [Amurz] + $/ / matches a string of 26 English letters in uppercase
^ [amurz] + $/ / matches a string of 26 lowercase letters
^ [A-Za-z0-9] + $/ / matches a string of numbers and 26 letters
^\ w match $/ / match a string consisting of numbers, 26 letters, or underscores
Commentary: some of the most basic and most commonly used expressions
/ the first 4 lines are used to protect js code from being downloaded
/ / basic regular expression /
/ / non-empty verification
Function NotNull (str) {return (stringing = "");}
/ / email address verification
Function checkEmail (str) {
/ / regular expression of email address
IsEmail1=/ ^\ w + ([\.\ -]\ w +) *\ @\ w + ([\.\ -]\ w +) *.
/ / regular expression of email address
IsEmail2=/. * @ [^ _] * $/
/ / verify the email address and return the result
Return (isEmail1.test (str) & & isEmail2.test (str);}
/ / ID card verification
Function checkIDCard (str) {
/ / ID card regular expression (15 bits)
IsIDCard1=/ ^ [1-9]\ d {7} ((0\ d) | (1 [0-2])) (([0 | 1 | 2]\ d) | 3 [0-1])\ d {3} $/
/ / ID card regular expression (18 bits)
IsIDCard2=/ ^ [1-9]\ d {5} [1-9]\ d {3} ((0\ d) | (1 [0-2])) (([0 | 1 | 2]\ d) | 3 [0-1]))\ d {4} $/
/ / verify the ID card and return the result
Return (isIDCard1.test (str) | | isIDCard2.test (str);}
/ / IP verification
Function checkIP (str) {
/ / IP regular expression
IP=' (25 [0-5] | 2 [0-4]\\ d | 1\\ d\\ d |\\ d\ d |\\ d)'; IPdot=IP+'\\.; isIPaddress=new RegExp ('^'+ IPdot+IPdot+IPdot+IP+'$')
/ / verify IP and return the result
Return (isIPaddress.test (str));}
/ / Home page (URL) verification
Function checkHomepage (str) {
/ / Home page regular expression
/ / isHomepage=/ ^\ w + ([\.\ -]\ w) * $/; isHomepage=/ ^\ w + (\.\ w +) +\.
/ / verify the home page and return the result
Return (isHomepage.test (str));}
/ / whether it is a number or not
Function isNum (str) {/ / isNumber=/ ^ ([1-9]\ d * (\.\ d +)?) | (\ d + (\.\ d +)) $/; isNumber=/ ^\ d + (\.\ d +)? $/
/ / verify and return the result
Return (isNumber.test (str));}
/ / whether it is an integer
Function isInt (str) {isInteger=/ ^\ dcards /
/ / verify and return the result
Return (isInteger.test (str));}
/ / whether it is a letter or not
Function isChar (str) {isCharacter=/ ^ [A-Za-z] + $/
/ / verify and return the result
Return (isCharacter.test (str));}
/ basic popup window /
Function checkBoolean (bv,i,w) {if (bv==false) {try {i.focus ();} catch (e) {} alert (w); return false;} return true}
/ element and value judgment /
Selected
Function checkElement_selected (item,alert_str) {if (item.type== "select-one") return checkElement_NotNull (item,alert_str); if (alert_str.length==0) alert_str=item.title+ "is required!" ; rt=false; if (item.length > 0) {for
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.