js Common expressions in work:
1) 2010-09-10 Type Date Check
2) Judging positive integers, string lengths
3) Check length, and whether empty
4) Determine if the string is empty
5) Compare character sizes
6) Determine the length of the string
7) Determine if the format is e-mail format
8) Determine whether it is two decimal places
9) Decide whether to include Chinese
10) Determine if a string is included
11) Judging whether it is a number
12) Determine whether a positive integer
13) Judging the combination of English characters and numbers
IP format Judgment
Ext.require ([' * ']);/*** * Date Check * @param {} num * @return {} */function testdate (newdate) {alert (newdate); var startime=ext.util.format.date (newdate, ' y-m-d h:m:s '); var startdatetemp = Startime.split (""); reg=/^ ([1-2]\d{3}) [\/|\-] (0?[ 1-9]|10|11|12) [\/|\-] ([1-2]?[ 0-9]|0[1-9]|30|31) $/; if (!startdatetemp[0].match (reg)) {Ext.Msg.alert ("System Prompt", "Please select the correct date format such as: 2010-09-10!!"); return false; } return true; Determine positive integer, string length function Checknumandlen (abc,lennum) {//Judgment null if (!checknull (ABC)) {//Judgment positive integer var reg =/^[0-9]+[0-9]*]*$/; Determines whether a string is a numeric/^[0-9]+.? [0-9]*$/if (!abc.match (reg)) {return false; }return Checklenth (abc,lennum);} return false;} Judging positive integers, string lengths function Checknumandnumlen (abc,lennum) {//judging null if (!checknull (ABC)) {//Judging positive integer var pattern =/^[0-9]+[0-9]*]* $/; Determines whether a string is a numeric/^[0-9]+.? [0-9]*$/if (Pattern.test (ABC)) {if (abc.length <= lennum) {return false;} Else{return true;}} else{return true;}} Else{return true;}} Verify the length, and whether the null//checksum is successfully returned true failed Falsefunction Checknullandlength (Abc,num) {if (!checknull (ABC)) {return checklenth (abc,num);} return false;} Determines whether the null function checknull (ABC) {if (ABC = = NULL | | abc.replace (/^\s\s*/, "). Replace (/\s\s*$/,"). Length = = 0) { return true; }return false;} /** * Compare Size * @param from * @param to * @returns {number} */function compare (From,to) {if (from>to) {return 1;} else if (from==to) {return 0;} else if (from<to) {return-1;}} Determine the string length function Checklenth (abc,lennum) {if (Lennum = = 0 | | abc = = NULL) {return true;} var L = 0; var a = Abc.split (""); for (Var i=0;i<a.length;i++) {if (a[i].charcodeat (0) <299) {l++; } else {l+=2; }} if (L > Lennum) {return false;} return true;} Phone number function Checkphone (strnumber) {var pattern =/^\d{0,20}$/;if (strnumber==null| | strnumber== "") {return true;} Else{if (Pattern.test (Strnumber)) {return true;}} return false;} Emailfunction Checkemail (stremail) {varpattern=/^ ([a-za-z0-9_-]) [email protected] ([a-zA-Z0-9_-]) + (\.[ A-za-z0-9_-]) +/;if (Pattern.test (Stremail)) return True; return false;} 2-bit decimal function isdecimal (value) {if (value = = null) return False;var v = Value;var pattern =/^[1-9]+\.\d{1,2}$/;flag = Patte Rn.test (v); if (!flag) {//obj.value = Obj.value + ". xx";//obj.select ();//obj.focus (); return false;} Else{return true;}} Contains Chinese//true: Contains Chinese false: does not contain Chinese function checkchinese (str) {if (Escape (str). IndexOf ("%u")! =-1) {return Tru E } else {return false; }}//Whether it contains special characters function checkquote (str) {var items = new Array ("~", "'", "!", "@", "#", "$", "%", "^", "&", "*", "{ ", "}", "[", "]", "(", ")","'"); Items.push (":", ";", "'", "|", "\ \", "<", ">", "?", "/", "<<", ">>", "| |", "//"); Items.push ("admin", "Administrators", "Administrator"); Items.push ("Select", "Delete", "Update", "Insert", "create", "drop", "alter", "Trancate"); str = Str.tolowercase (); for (var i = 0; i < items.length; i++) {if (Str.indexof (items[i]) >= 0) {return true; } } return false; }//is the number function Checknum (str) {var pattern =/^[0-9]*$/; if (Pattern.test (str)) {return false; }else{return true; }}//Whether it is a positive integer function Checkpositivenum (str) {//Judgment null if (!checknull (str)) {//Judgment positive integer var reg =/^[1-9]+[0-9]*]*$/; Determines whether a string is a numeric/^[0-9]+.? [0-9]*$/if (Str.match (reg)) {return false; }else{return true;}} return true;} /** * Determine if the file format is correct * @param {Object} str * @return {TypeName} */function checkfile (str) {//Verify the regular var img_reg of the picture file = /\. ([vv][mm]) {1}$/; if (Str.match (Img_reg)) {return false; }else{return true; }}/** * Determine if the file format is correct * @param {Object} str * @return {TypeName} */function checkfileexcel (str) {//verify the regular var im of the picture file G_reg =/\. ([XX][LL][SS]) {1}$/; if (Str.match (Img_reg)) {return false; }else{return true; }}//can only be English characters with the number combination function Checkatandnumber (str,strlength) {var qtype=/^[a-za-z0-9]+$/; if (Str.match (Qtype)) {if (!checklenth (str,strlength)) {return false; }else{return true; } }else{return false; }}/** * IP format judgment * @param {object} str * @param {object} strlength * @return {TypeName} */function Checki P (str) {var pattern =/^ (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. ( \D{1,2}|1\D\D|2[0-4]\D|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) $/; if (Pattern.test (str)) {return false; }else{return true; } }
JS Common Regular expression "share"