Some common Regular Expressions in JavaScript (recommended) and javascript Regular Expressions

Source: Internet
Author: User

Some common Regular Expressions in JavaScript (recommended) and javascript Regular Expressions

A regular expression (regular expression) describes a string matching pattern, it can be used to check whether a string contains a seed string, replace matched substrings, or retrieve substrings that meet certain conditions from a string.

Var validateRegExp = {decmal: "^ ([+-]?) \ D *\\. \ d + $ ", // floating point decmal1:" ^ [1-9] \ d *. \ d * | 0. \ d * [1-9] \ d * $ ", // Positive floating point decmal:" ^-([1-9] \ d *. \ d * | 0. \ d * [1-9] \ d *) $ ", // negative floating point number decm_3:" ^ -? ([1-9] \ d *. \ d * | 0. \ d * [1-9] \ d * | 0 ?. 0 + | 0) $ ", // floating point 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 + | 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 number (positive integer + 0) num2: "^-[1-9] \ d * | 0 $", // negative (negative integer + 0) ascii: "^ [\ x00-\ xFF] + $", // only chinese characters of acⅱ: "^ [\ 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] + $ ", // email idcard:" ^ [1-9] ([0-9] {14} | [0-9] {17 }) $ ", // ID card 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 letter_l: "^ [a-z] + $", // lowercase letter letter_u: "^ [A-Z] + $", // uppercase letter mobile: "^ 0? (13 | 15 | 18 | 14 | 17) [0-9] {9} $ ", // notempty:" ^ \ S + $ ", // non-empty password: "^. * [A-Za-z0-9 \ w _-] +. * $ ", // password fullNumber:" ^ [0-9] + $ ", // number picture :"(. *)\\. (jpg | bmp | gif | ico | pcx | jpeg | tif | png | raw | tga) $ ", // qq: "^ [1-9] * [1-9] [0-9] * $", // QQ number rar :"(. *)\\. (rar | zip | 7zip | tgz) $ ", // zip file tel:" ^ [0-9 \-()] {7, 18} $ ", // call number function (including domestic area code, international area code, and extension code) url: "^ http [s]?: \/([\ W-] + \.) + [\ w-] + ([\ w -./? % & =] *)? $ ", // Urlusername:" ^ [A-Za-z0-9 _ \-\ u4e00-\ u9fa5] + $ ", // account name deptname:" ^ [A-Za-z0-9 _() () \-\ u4e00-\ u9fa5] + $ ", // unit name zipcode:" ^ \ d {6} $ ", // zip code 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: function (str) {return 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 (str1 = 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 "). val (); // 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 ;}; // sleep (numberMillis) {var now = new Date (); var exitTime = now. getTime () + numberMillis; while (true) {now = new Date (); if (now. getTime ()> exitTime) return ;}}

The above section describes some common Regular Expressions (recommended) in JavaScript. I hope this will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.