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 introduces the knowledge of "regular expression instance usage in JavaScript". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The approximate matching process of a regular expression is to compare the expression with the characters in the text in turn, and if every character can match, the match is successful; once there are unsuccessful characters, the match fails.
Regular expressions are often used to find matching strings in text. The default quantifier in Python is greedy (or, in a few languages, it may be non-greedy), always trying to match as many characters as possible; non-greedy, on the contrary, always trying to match as few characters as possible. For example: the regular expression "ab*" will find "abbb" if it is used to find "abbbc". If you use the non-greedy quantifier "ab*?", you will find "a".
Var pageIndex=document.getElementById ("textfield"). Value;if (! / ^ [0-9] + $/ .test (pageIndex)) {alert ("Please enter a positive integer"); return false;} else {alert ("enter a positive integer");} / determine whether the input is empty function IsNull () {var str = document.getElementById ('str'). Value.trim (); if (str.length==0) {alert (' Sorry, 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: / ^ (\ (\ d {2pr 3}\)) | (\ d {3}\ -))? (\ (0\ d {2jue 3}\) | 0\ d {2jue 3} -)? [1-9]\ d {6jue 7} (\ -\ d {1jue 4})? $/
Mobile: / ^ (\ (\ d {2jue 3}\)) | (\ d {3}\ -))? 13\ d {9} $/
Url: / ^ http:\ /\ / [A-Za-z0-9] +\. [A-Za-z0-9] + [\ / =\?%\-& _ ~ `@ [\]: +!] * ([^\ "\"]) * $/
IdCard: / ^\ d {15} (\ d {2} [A-Za-z0-9])? $/
QQ: / ^ [1-9]\ d {4jin8} $/
Some kind of special amount: / ^ ((\ d {1jue 3} (,\ d {3}) *) | (\ d +)) (\.\ d {2})? $/ / description: except for "XXX XX,XXX XX,XXX.00" format
/ / provide .trim () attribute for each JS authentication method provided above
String.prototype.trim=function () {return this.replace (/ (^\ s *) | (\ s $) / g, ");}
Call:
/ / write the JS verification function you want to call in onClick
Js validation form js submit validation class
Attach: js verifies that radio is selected
Function checkform (obj) {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.