In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the verification method of JS regular expression". In the daily operation, I believe that many people have doubts about the verification method of JS regular expression. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "verification method of JS regular expression". Next, please follow the editor to study!
/ / determine whether the input is empty function IsNull () {var str = document.getElementById ('str'). Value.trim (); if (str.length==0) {alert (' Sorry, the text box cannot be empty or blank!') / / Please change the "text box" to the name of the attribute you need to verify!}} / / determine whether the date type is in YYYY-MM-DD format function IsDate () {var str = document.getElementById ('str'). Value.trim (); if (str.dater) {var reg = / ^ (\ d {1pm 4}) (- |\ |\ d {1pm 2}))\ 2 (\ d {1pm 2}) /; var r = str.match (reg) If (r==null) alert ('sorry, the date you entered is not in the correct format!'); / / Please change the "date" to the name of the attribute you need to verify!} / / determine whether the date type is the YYYY-MM-DD hh:mm:ss format type function IsDateTime () {var str = document.getElementById ('str'). Value.trim () If (str.recording 2}) {var reg = / ^ (\ d {1meme4}) (- |\ /) (\ d {1meme2})\ 2 (\ d {1Power2})) (\ d {1Magne2}): (\ d {1mem2}) $/; var r = str.match (reg); if (r==null) alert ('Sorry, the date you entered is not in the correct format!') / / Please change the "date" to the attribute name you need to verify!}} / / determine whether the date type is the hh:mm:ss format type function IsTime () {var str = document.getElementById ('str'). Value.trim () If (str.dater str 0) {reg=/ ^ ((20 | 21 | 22 | 23 | [0-1]\ d)\: [0-5] [0-9]) (\: [0-5] [0-9])? $/ if (! reg.test (str)) {alert ("Sorry, the date you entered is not in the correct format!") / / Please change the "date" to the name of the attribute you need to verify!} / / determine whether the characters entered are the letters function IsLetter () {var str = document.getElementById ('str'). Value.trim (); if (str.datedate 0) {reg=/ ^ [a-zA-Z] + $/; if (! reg.test (str)) {alert ("Sorry, the letter type you entered is not in the correct format!") / / Please change the "alphabet type" to the name of the attribute you need to verify!} / / determine whether the input character is an integer function IsInteger () {var str = document.getElementById ('str'). Value.trim (); if (str.alphanumeric type 0) {reg=/ ^ [- +]?\ dalphabet; if (! reg.test (str)) {alert ("Sorry, the integer type you entered is not in the correct format!") / / Please replace the "integer type" with the name of the attribute you want to verify! } / / determine whether the character entered is a double-precision function IsDouble (val) {var str = document.getElementById ('str'). Value.trim (); if (str.roomthread0) {reg=/ ^ [-\ +]?\ d + (\.\ d +)? $/; if (! reg.test (str)) {alert ("Sorry, the double type you entered is not in the correct format!") / / Please replace the "double precision type" with the name of the attribute you want to verify! } / / determine whether the input character is: a str' ZJ 0-9 function IsString () {var str = document.getElementById ('str'). Value.trim (); if (str.string characters) {reg=/ ^ [a-zA-Z0-9 _] + $/; if (! reg.test (str)) {alert ("Sorry, the string type you entered is not in the correct format!") / / Please replace the "string type" with the name of the attribute you want to verify! } / / determine whether the input character is Chinese function IsChinese () {var str = document.getElementById ('str'). Value.trim (); if (str.string _ types0) {reg=/ ^ [\ u0391 -\ uFFE5] + $/; if (! reg.test (str)) {alert ("Sorry, the string type you entered is not in the correct format!"); / / Please replace the "string type" with the attribute name you want to verify! } / / determine whether the input EMAIL format is correct: function IsEmail () {var str = document.getElementById ('str'). Value.trim (); if (str.roomthread0) {reg=/ ^\ w + ([- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) * $/; if (! reg.test (str)) {alert ("Sorry, the string you entered is not in the correct format!") / / Please replace the "string type" with the name of the attribute you want to verify! } / / determine whether the zip code entered (only six digits) is correct function IsZIP () {var str = document.getElementById ('str'). Value.trim (); if (str.string _ types0) {reg=/ ^\ d {6} $/; if (! reg.test (str)) {alert ("Sorry, the string type you entered is not in the correct format!"); / / Please replace the "string type" with the attribute name you want to verify! } / / determine that the input number is less than a specific number function MaxValue () {var val = document.getElementById ('str'). Value.trim (); if (str.roomthread0) {reg=/ ^ [- +]?\ dnumbers If (! reg.test (str)) {/ / determine whether it is the number type if (val > parseInt ('123')) / / the maximum value set for yourself {alert (' sorry, the number you entered is out of range'); / / please change the "number" to the attribute name you want to verify! } Phone: / ^ var r = str.match (reg); if (r==null) alert ('Sorry, the date you entered is not in the correct format!') / / Please change the "date" to the attribute name you need to verify!}} / / determine whether the date type is the YYYY-MM-DD hh:mm:ss format type function IsDateTime () {var str = document.getElementById ('str'). Value.trim () If (str.recording 2}) {var reg = / ^ (\ d {1meme4}) (- |\ /) (\ d {1meme2})\ 2 (\ d {1Power2})) (\ d {1Magne2}): (\ d {1mem2}) $/; var r = str.match (reg); if (r==null) alert ('Sorry, the date you entered is not in the correct format!') / / Please change the "date" to the attribute name you need to verify!}} / / determine whether the date type is the hh:mm:ss format type function IsTime () {var str = document.getElementById ('str'). Value.trim () If (str.dater str 0) {reg=/ ^ ((20 | 21 | 22 | 23 | [0-1]\ d)\: [0-5] [0-9]) (\: [0-5] [0-9])? $/ if (! reg.test (str)) {alert ("Sorry, the date you entered is not in the correct format!") / / Please change the "date" to the name of the attribute you need to verify!} / / determine whether the characters entered are the letters function IsLetter () {var str = document.getElementById ('str'). Value.trim (); if (str.datedate 0) {reg=/ ^ [a-zA-Z] + $/; if (! reg.test (str)) {alert ("Sorry, the letter type you entered is not in the correct format!") / / Please change the "alphabet type" to the name of the attribute you need to verify!} / / determine whether the input character is an integer function IsInteger () {var str = document.getElementById ('str'). Value.trim (); if (str.alphanumeric type 0) {reg=/ ^ [- +]?\ dalphabet; if (! reg.test (str)) {alert ("Sorry, the integer type you entered is not in the correct format!") / / Please replace the "integer type" with the name of the attribute you want to verify! } / / determine whether the character entered is a double-precision function IsDouble (val) {var str = document.getElementById ('str'). Value.trim (); if (str.roomthread0) {reg=/ ^ [-\ +]?\ d + (\.\ d +)? $/; if (! reg.test (str)) {alert ("Sorry, the double type you entered is not in the correct format!") / / Please replace the "double precision type" with the name of the attribute you want to verify! } / / determine whether the input character is: a str' ZJ 0-9 function IsString () {var str = document.getElementById ('str'). Value.trim (); if (str.string characters) {reg=/ ^ [a-zA-Z0-9 _] + $/; if (! reg.test (str)) {alert ("Sorry, the string type you entered is not in the correct format!") / / Please replace the "string type" with the name of the attribute you want to verify! } / / determine whether the input character is Chinese function IsChinese () {var str = document.getElementById ('str'). Value.trim (); if (str.string _ types0) {reg=/ ^ [\ u0391 -\ uFFE5] + $/; if (! reg.test (str)) {alert ("Sorry, the string type you entered is not in the correct format!"); / / Please replace the "string type" with the attribute name you want to verify! } / / determine whether the input EMAIL format is correct: function IsEmail () {var str = document.getElementById ('str'). Value.trim (); if (str.roomthread0) {reg=/ ^\ w + ([- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) * $/; if (! reg.test (str)) {alert ("Sorry, the string you entered is not in the correct format!") / / Please replace the "string type" with the name of the attribute you want to verify! } / / determine whether the zip code entered (only six digits) is correct function IsZIP () {var str = document.getElementById ('str'). Value.trim (); if (str.string _ types0) {reg=/ ^\ d {6} $/; if (! reg.test (str)) {alert ("Sorry, the string type you entered is not in the correct format!"); / / Please replace the "string type" with the attribute name you want to verify! } / / determine that the input number is less than a specific number function MaxValue () {var val = document.getElementById ('str'). Value.trim (); if (str.roomthread0) {reg=/ ^ [- +]?\ dnumbers / If (! reg.test (str)) {/ / determine whether it is the number type if (val > parseInt ('123')) / / the maximum value set for yourself {alert (' sorry, the number you entered is out of range'); / / please change the "number" to the attribute name you want to verify! } Phone: / ^ (\ (\ d {2jue 3}\)) | (\ d {3}\))? (\ (0\ d {2jue 3}\) | 0\ d {2jue 3} -)? [1-9]\ d {6 − 7} (\ -\ d {1jue 4})? / Mobile: / ^ ((\ d {3} 3) | (\ d {3}\ -))? 13\ d {9} / Url:/http:\ /\ / [A − Za − z0 − 9] +\. [A − Za − Z0 − 9] + [\ / =\? / Url:/http:\ /\ / [A − Za − z0 − 9] +\. [A − Za − z0 − 9] + [\ / =\? / IdCard: / ^\ d {15} (\ d {2} [A-Za-z0-9])? / QQ:/ [1 − 9]\ d4 lead 8QQRank / [1 − 9]
Some kind of special amount: / ^ ((\ d {1jue 3} (,\ d {3}) *) | (\ d +)) (\.\ d {2})? $/
/ / description: in addition to the "XXX XX,XXX XX,XXX.00" format / / provide the .trim () attribute String.prototype.trim=function () {return this.replace (/ (^\ s *)) / g, "");} for each JS authentication method provided above.
Call:
/ / write the JS verification function that you want to call in onClick. This is the end of the study on "the verification method of JS regular expression". I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.