Copy Code code as follows:
/*
Purpose: Verify the format of IP address
Input: Strip:ip Address
Returns: False if return true through validation;
*/
function IsIP (StrIP) {
if (IsNull (StrIP)) return false;
var re =/^ (\d+) \. (\d+) \. (\d+) \. (\d+) $/g//matching the regular expression of the IP address
if (Re.test (StrIP)) {
if (Regexp.$1 < 256 && regexp.$2 < 256 && regexp.$3 < 256 && regexp.$4 < 256) return T Rue
}
return false;
}
/*
Purpose: Check if the input string is empty or all are spaces
Input: str
Return:
Returns true if all is null, or False
*/
function IsNull (str) {
if (str = = "") return true;
var Regu = "^[]+$";
var re = new RegExp (Regu);
return Re.test (str);
}
/*
Purpose: Check whether the value of the input object conforms to the integer format
Input: str input string
Return: False if return true through validation
*/
function Isinteger (str) {
var regu =/^[-]{0,1}[0-9]{1,}$/;
return Regu.test (str);
}
/*
Purpose: Check whether the input mobile phone number is correct
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Checkmobile (s) {
var regu =/^[1][0-9][0-9]{9}$/;
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
} else {
return false;
}
}
/*
Purpose: Check if the input string conforms to the positive integer format
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isnumber (s) {
var Regu = "^[0-9]+$";
var re = new RegExp (Regu);
if (S.search (re)!=-1) {
return true;
} else {
return false;
}
}
/*
Purpose: Check if the input string is a decimal number format, can be negative
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isdecimal (str) {
if (Isinteger (str)) return true;
var re =/^[-]{0,1} (\d+) [\.] + (\d+) $/;
if (Re.test (str)) {
if (regexp.$1 = = 0 && regexp.$2 = 0) return false;
return true;
} else {
return false;
}
}
/*
Purpose: Check if the value of the input object conforms to the port number format
Input: str input string
Return: False if return true through validation
*/
function Isport (str) {
Return (Isnumber (str) && str < 65536);
}
/*
Purpose: Check if the value of the input object conforms to the e-mail format
Input: str input string
Return: False if return true through validation
*/
function Isemail (str) {
var myreg =/^[-_a-za-z0-9]+@ ([_a-za-z0-9]+\.) +[a-za-z0-9]{2,3}$/;
if (Myreg.test (str)) return true;
return false;
}
/*
Purpose: Check whether the input string conforms to the amount format
The format is defined as a positive number with decimals, with a maximum of three digits after the decimal point
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Ismoney (s) {
var Regu = "^[0-9]+[\." [0-9] {0,3}$ ";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
} else {
return false;
}
}
/*
Purpose: Check if the input string is composed of English letters and numbers and underscores only
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isnumberor_letter (s) {//Judge whether it is a number or letter
var Regu = "^[0-9a-za-z\_]+$";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
} else {
return false;
}
}
/*
Purpose: Check if the input string is made up of English letters and numbers only
Input:
S: string
Return:
Returns False if the validation returns true
*/
function Isnumberorletter (s) {//Judge whether it is a number or letter
var Regu = "^[0-9a-za-z]+$";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
} else {
return false;
}
}
/*
Purpose: Check if the input string is composed of Chinese characters, letters and numbers only
Input:
Value: String
Return:
Returns False if the validation returns true
*/
function Ischinaornumborlett (s) {//Judge whether it is Chinese characters, letters, numbers
var Regu = "^[0-9a-za-z\u4e00-\u9fa5]+$";
var re = new RegExp (Regu);
if (Re.test (s)) {
return true;
} else {
return false;
}
}
/*
Use: Determine whether the date
Enter: Date: dates; FMT: date format
Return: False if return true through validation
*/
function isDate (date, FMT) {
if (FMT = = null) FMT = "YYYYMMDD";
var yindex = fmt.indexof ("yyyy");
if (Yindex = = 1) return false;
var year = date.substring (Yindex, Yindex + 4);
var mindex = Fmt.indexof ("MM");
if (Mindex = = 1) return false;
var month = date.substring (Mindex, Mindex + 2);
var dindex = Fmt.indexof ("dd");
if (Dindex = = 1) return false;
var day = date.substring (Dindex, Dindex + 2);
if (!isnumber) | | | | | | | | | | | year < "1900") return false;
if (!isnumber (month) | | | month > "| | | | month <") return false;
if (Day > Getmaxday (Year, month) | |/day < "a") return false;
return true;
}
Function Getmaxday (year, month) {
if (month = 4 | | month = 6 | | | month = 9 | | month = = 11)
return "30";
if (month = 2)
if (year% 4 = 0 && Year%!= 0 | |-year% 400 = 0)
return "29";
Else
Return "28";
return "31";
}
/*
Usage: Character 1 ends with string 2
Input: str1: string; str2: contained string
Return: False if return true through validation
*/
function Islastmatch (str1, str2) {
var index = str1.lastindexof (STR2);
if (str1.length = = index + str2.length) return true;
return false;
}
/*
Usage: Character 1 starts with string 2
Input: str1: string; str2: contained string
Return: False if return true through validation
*/
function Isfirstmatch (str1, str2) {
var index = str1.indexof (STR2);
if (index = = 0) return true;
return false;
}
/*
Purpose: Character 1 is the containing string 2
Input: str1: string; str2: contained string
Return: False if return true through validation
*/
function IsMatch (str1, str2) {
var index = str1.indexof (STR2);
if (index = = 1) return false;
return true;
}
/*
Purpose: Check that the input start and end date is correct, the rule is two date of the correct format,
And end the scheduled >= start date
Input:
StartDate: Start Date, string
EndDate: End as scheduled, string
Return:
Returns False if the validation returns true
*/
function Checktwodate (StartDate, EndDate) {
if (!isdate (StartDate)) {
Alert ("Incorrect start date!");
return false;
else if (!isdate (EndDate)) {
Alert ("Incorrect end date!");
return false;
else if (StartDate > EndDate) {
Alert ("Start date cannot be greater than End date!");
return false;
}
return true;
}
/*
Purpose: Check the format of email box entered correctly
Input:
Stremail: String
Return:
Returns False if the validation returns true
*/
function Checkemail (stremail) {
var emailreg =/^[_a-z0-9]+@ ([_a-z0-9]+\.) +[a-z0-9]{2,3}$/;
var Emailreg =/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$/;
if (Emailreg.test (Stremail)) {
return true;
} else {
Alert ("The email address you entered is not in the correct format!") ");
return false;
}
}