/*****************************************************************
Form validation Tool Class (LINJQ)
*****************************************************************/
/**
* Determine if integer num equals 0
*
* @param num
* @return
* @author Jiqinlin
*/
function Isinteqzero (num) {
return num==0;
}
/**
* Determine if integer num is greater than 0
*
* @param num
* @return
* @author Jiqinlin
*/
function Isintgtzero (num) {
Return num>0;
}
/**
* Determine if integer num is greater than or equal to 0
*
* @param num
* @return
* @author Jiqinlin
*/
function Isintgtezero (num) {
Return num>=0;
}
/**
* Determine if the floating-point number num equals 0
*
* @param num Floating-point number
* @return
* @author Jiqinlin
*/
function Isfloateqzero (num) {
return num==0;
}
/**
* Determine if the floating-point number num is greater than 0
*
* @param num Floating-point number
* @return
* @author Jiqinlin
*/
function Isfloatgtzero (num) {
Return num>0;
}
/**
* Determine if the floating-point number num is greater than or equal to 0
*
* @param num Floating-point number
* @return
* @author Jiqinlin
*/
function Isfloatgtezero (num) {
Return num>=0;
}
/**
* Match Email address
*/
function Isemail (str) {
if (str==null| | str== "") return false;
var result=str.match (/^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/);
if (result==null) return false;
return true;
}
/**
* Determine numeric types, including integers and floating-point numbers
*/
function Isnumber (str) {
if (isdouble (str) | | isinteger (str)) return true;
return false;
}
/**
* Only numbers can be entered [0-9]
*/
function Isdigits (str) {
if (str==null| | str== "") return false;
var result=str.match (/^\d+$/);
if (result==null) return false;
return true;
}
/**
* Match Money
*/
function Ismoney (str) {
if (str==null| | str== "") return false;
var result=str.match (/^ ([1-9]\d*) | ( ([0-9]{1}| [1-9]+] \. [0-9] {)}) $/);
if (result==null) return false;
return true;
}
/**
* Match Phone
*/
function Isphone (str) {
if (str==null| | str== "") return false;
var result=str.match (/^ (\ (\d{2,3}\)) | ( \d{3}\-))? (\ (0\d{2,3}\) |0\d{2,3}-)? [1-9]\d{6,7} (\-\d{1,4})? $/);
if (result==null) return false;
return true;
}
/**
* Match Mobile
*/
function IsMobile (str) {
if (str==null| | str== "") return false;
var result=str.match (/^ (\ (\d{2,3}\)) | ( \d{3}\-))? ((13\d{9}) | (15\d{9}) | (18\d{9})) $/);
if (result==null) return false;
return true;
}
/**
* Contact Phone (phone/Phone) verification
*/
function Istel (String text) {
if (ismobile (text) | | Isphone (text)) return true;
return false;
}
/**
* Matching QQ
*/
function isqq (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[1-9]\d{4,12}$/);
if (result==null) return false;
return true;
}
/**
* Match 中文版
*/
function Isenglish (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[a-za-z]+$/);
if (result==null) return false;
return true;
}
/**
* Match integer
*/
function Isinteger (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[-\+]?\d+$/);
if (result==null) return false;
return true;
}
/**
* Match Double or float
*/
function Isdouble (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[-\+]?\d+ (\.\d+) $/);
if (result==null) return false;
return true;
}
/**
* Match zip Code
*/
function Iszipcode (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[0-9]{6}$/);
if (result==null) return false;
return true;
}
/**
* Match URL
*/
function Isurl (str) {
if (str==null| | str== "") return false;
var Result=str.match (/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\]) *$/);
if (result==null) return false;
return true;
}
/**
* Match password, start with a letter, length between 6-12, can only contain characters, numbers and underscores.
*/
function Ispwd (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[a-za-z]\\w{6,12}$/);
if (result==null) return false;
return true;
}
/**
* Determine if it is a valid character (a-za-z0-9-_)
*/
function isrightfulstring (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[a-za-z0-9_-]+$/);
if (result==null) return false;
return true;
}
/**
* Match 中文版
*/
Function isenglish (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[a-za-z]+$/);
if (result==null) return false;
return true;
}
/**
* matches the ID number
*/
Function Isidcardno (num) {
//if (IsNaN (num)) {alert ("input is not a number! "); return false;}
var len = num.length, re;
if (len = =)
Re = new RegExp (/^ (\d{6}) ()? ( \D{2}) (\d{2}) (\d{2}) (\d{2}) (\w) $/);
Else if (len = =)
Re = new RegExp (/^ (\d{6}) ()? ( \D{4}) (\d{2}) (\d{2}) (\d{3}) (\w) $/);
Else {alert ("The number of digits entered is incorrect. "); return false;}
var a = Num.match (re);
if (a! = null)
{
if (len==15)
{
var D = new Date ("+a[3]+"/"+a[4]+"/"+a[5]);
var B = d.getyear () ==a[3]&& (D.getmonth () +1) ==a[4]&&d.getdate () ==a[5];
}
Else
{
var D = new Date (a[3]+ "/" +a[4]+ "/" +a[5]);
var B = d.getfullyear () ==a[3]&& (D.getmonth () +1) ==a[4]&&d.getdate () ==a[5];
}
if (! B) {alert ("entered ID number" + a[0] + "The date of birth is incorrect. "); return false;}
}
if (!re.test (num)) {alert ("The last digit of the ID can only be a number and a letter.") "); return false;}
return true;
}
/**
* Match Chinese characters
*/
function Ischinese (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[\u4e00-\u9fa5]+$/);
if (result==null) return false;
return true;
}
/**
* Match Chinese (including Kanji and characters)
*/
function Ischinesechar (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[\u0391-\uffe5]+$/);
if (result==null) return false;
return true;
}
/**
* Character verification, can only contain Chinese, English, numerals, underscores and other characters.
*/
function Stringcheck (str) {
if (str==null| | str== "") return false;
var result=str.match (/^[a-za-z0-9\u4e00-\u9fa5-_]+$/);
if (result==null) return false;
return true;
}
/**
* Filter Chinese and English special characters, except English "-_" characters
*/
function Stringfilter (str) {
var pattern = new RegExp ("[' [Email protected]#$%^&* () +=|{} ':; ', \\[\\].<>/?~! @#¥%......&* ()--+| {}【】‘;:”“’。 ,、? ]");
var rs = "";
for (var i = 0; i < str.length; i++) {
rs = rs + str.substr (I, 1). replace (pattern, ');
}
Return RS;
}
/**
* To determine whether to include Chinese and English special characters, except English "-_" characters
*/
function Iscontainsspecialchar (str) {
if (str==null| | str== "") return false;
var reg = RegExp (/[(\) (\ ') (\~) (\!) (\@) (\#) (\$) (\%) (\^) (\&) (\*) (\ () (\)) (\+) (\=) (\|) (\{)(\}) (\‘) (\:)(\;)(\‘)(‘,)(\[)(\])(\.) (\<) (\>) (\/) (\?) (\~) (\! ) (\@) (\#) (\¥) (\%) (\ ...) (\&) (\*) (\() (\)) (\—) (\+) (\|) (\{)(\}) (\【) (\】) (\‘) (\;) (\:) (\”) (\“) (\’) (\。 )(\,)(\、)(\? )]+/);
return Reg.test (str);
}
The history of the most complete JS Form validation Encapsulation class