Some common regular expressions in JavaScript (recommended) _ Regular expressions

Source: Internet
Author: User
Tags rar

The

  Regular expression (regular expression) describes a string matching pattern that can be used to check whether a string contains a seed string, replaces a matching substring, or extracts a substring from a string that matches a condition.

var validateregexp = {decmal: "^ ([+-]?) \\d*\\.\\d+$ ",//floating-point number decmal1:" ^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$ ",//Positive floating-point number decmal2:" ^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d* ) $ ",//Negative floating-point number decmal3:" ^-? ([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?. 0+|0) $ ",//floating-point number decmal4:" ^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0? 0+|0$ ",//Non-negative floating-point number (positive floating-point number + 0) DECMAL5:" ^ (-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)) |? 0+|0$,//non-positive floating-point number (negative floating-point number +//0) Intege: "^-?" [1-9]\\d*$,//Integer intege1: "^[1-9]\\d*$",//Positive integer intege2: "^-[1-9]\\d*$",//Negative integer num: "^ ([+-]?") \\d*\\.? \\d+$ ",//Number NUM1:" ^[1-9]\\d*|0$ ",//positive (positive integer + 0) num2:" ^-[1-9]\\d*|0$ ",//negative (negative integer + 0) ASCII:" ^[\\x00-\\xff]+$ ",//Only acsii character Chinese: "^[\\u4e00-\\u9fa5]+$",//Only Chinese color: "^[a-fa-f0-9]{6}$",//Color date: "^\\d{4}" (\\-|\\/|\.) \\d{1,2}\\1\\d{1,2}$ ",//Date Email:" ^\\w+ (-\\w+) | ( \\.\\w+)) *\\@[a-za-z0-9]+ (\\.| -) [a-za-z0-9]+) *\\. [a-za-z0-9]+$ ",//Mail Idcard:" ^[1-9] ([0-9]{14}|[ 0-9]{17}) $ ",//ID IP4:" ^ (25[0-5]|2[0-4]\\d|[ 0-1]\\d{2}| [1-9]?\\d] \. (25[0-5]|2[0-4]\\d| [0-1]\\d{2}| [1-9]?\\d] \. (25[0-5]|2[0-4]\\d| [0-1]\\d{2}| [1-9]?\\d] \. (25[0-5]|2[0-4]\\d| [0-1]\\d{2}| [1-9]?\\d) $ ",//IP address letter:" ^[a-za-z]+$ ",//letter_l:" ^[a-z]+$ ",//lowercase letter Letter_u:" ^[a-z]+$ ",//Capital Letter Mobile:" ^0 ? (13|15|18|14|17) [0-9] {9}$ ",//Mobile phone Notempty:" ^\\s+$ ",//Not empty password:" ^.*[a-za-z0-9\\w_-]+.*$ ",//Password Fullnumber:" ^[0-9]+$ ",//Digital Picture:" (.*)\\. (JPG|BMP|GIF|ICO|PCX|JPEG|TIF|PNG|RAW|TGA) $ ",//Picture QQ:" ^[1-9]*[1-9][0-9]*$ ",///QQ number RAR:" (. *) \. (rar|zip|7zip|tgz) $ ",//Compressed file Tel:" ^[0-9\-() ()]{7,18}$ ",//Phone number function (including verification of domestic area code, international area code, extension number) URL:" ^http[s]?:\ \/\\/([\\w-]+\\.) +[\\w-]+ ([\\w-./?%&=]*) $ ",//URL username:" ^[a-za-z0-9_\\-\\u4e00-\\u9fa5]+$ ",//Username deptname:" ^[a-za-z0-9_ "() () \\-\\u4e00-\\u9fa5]+$ ",//unit name ZipCode:" ^\\d{6}$ ",//Zip Realname:" ^[a-za-z\\u4e00-\\u9fa5]+$ ",//real name CompanyName:" ^[a-za-z0-9_ () () \\-\\u4e00-\\u9fa5]+$ ", Companyaddr:" ^[a-za-z0-9_ () () \\#\\-\\u4e00-\\u9fa5]+$ ", Companysite:" ^ Http[s]?:\ \/\\/([\\w-]+\\.)
+[\\w-]+ ([\\w-./?%&#=]*)? $ "}; Validation rule var ValidaTerules = {isnull:function (str) {return (str = = "" | |
typeof str!= "string"); }, Betweenlength:function (str, _min, _max) {return (str.length >= _min && str.length <= _max);}, Isuid:f Unction (str) {return to New RegExp (validateregexp.username). Test (str);}, Fullnumbername:function (str) {return new REGEXP
(validateregexp.fullnumber). Test (str); }, Ispwd:function (str) {return/^.* ([\w_a-za-z0-9-]) +.*$/i.test (str);}, Ispwdrepeat:function (str1, str2) {return (str
1 = = str2); }, Isemail:function (str) {return new RegExp (validateregexp.email). Test (str);}, Istel:function (str) {return new REGEXP
(Validateregexp.tel). Test (str);  Ismobile:function (str) {return new RegExp (validateregexp.mobile). Test (str); Checktype:function (Element) {return
(Element.attr ("type") = = "checkbox" | | element.attr ("type") = = "Radio" | | element.attr ("rel") = = "select"); }, Isrealname:function (str) {return new RegExp (validateregexp.realname). Test (str);, iscompanyname:function (str) {
return new RegExp (validateregexp.companyname). Test (str); }, Iscompanyaddr:function (str) {return new RegExp (VALIDATEREGEXP.COMPANYADDR). Test (str);}, Iscompanysite:function ( STR) {return new RegExp (validateregexp.companysite). Test (str);, simplepwd:function (str) {//var pin = $ ("#regName"). V
Al (); if (Pin.length > 0) {//pin = Strtrim (PIN);//if (pin = = str) {//return true;//}//} return Pwdlevel (str) = =
1;
}, Weakpwd:function (str) {for (var i = 0; i < weakpwdarray.length i++) {if (weakpwdarray[i] = = str) {return true;
return false;
}
}; Hibernate function Sleep (numbermillis) {var now = new Date (), var exittime = now.gettime () + Numbermillis; while (true)
= new Date ();
if (Now.gettime () > Exittime) return; }
}

The above is a small set of JavaScript to introduce some commonly used regular expressions (recommended), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.