The most comprehensive JavaScript Form Verification

Source: Internet
Author: User

The most comprehensive JavaScript Form Verification

 

Comparison of Two dates

 

/*
Purpose: Check whether the start date is less than or equal to the end date.
Input:
S: String Start Date Format: 2001-5-4

E: String End Date Format: 2002-5-4
Return Value:
If the start date is less than or equal to the end date, true is returned. Otherwise, false is returned.
*/

Function data_compare (s, e)
{
Var arr = s. split (-);
Var starttime = new Date (arr [0], arr [1], arr [2]);...

More date comparison information

Blank or all spaces

 

/*
Purpose: Check whether the input string is null or all are spaces.
Input: str
Return Value:
If all values are null, true is returned. Otherwise, false is returned.
*/
Function isNull (str ){
If (str =) return true;
Var regu = ^ [] + $;

.....

More blank or all space information

Determine whether it is a date

 

/*
Purpose: determine whether it is a date.
Input: date; matched format:

Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/

Function isDate (str ){
If (isNull (str) return false;
Var r = str. match (/^ (d {4}) (-|/) (d {1, 2}) (-|/) (d {1, 2}) $ /);
If (r = null) return false;
Var d = new Date (r [1], r [3]-1, r [5]);
...

More information about whether to determine the date

Letter/digit underline

 

/*
Purpose: Check whether the input string is composed of English letters, numbers, and underscores (_).
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/
Function isNumberOr_Letter (s) {// determines whether it is a number or letter
Var regu = ^ [0-9a-zA-Z _] + $;
Var re = new RegExp (regu );
If (re. test (s ))...

More letters, numbers, and underscores

Character 1 starts with string 2

 

/*
Purpose: whether character 1 starts with string 2
Input: str1: string; str2: contained string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/
Function isFirstMatch (str1, str2 ){
Var index = str1.indexOf (str2 );
If (index = 0) return true;
Return false;
}

More Character 1 starts with string 2

Character 1 ends with string 2

 

/*
Purpose: whether character 1 ends with string 2
Input: str1: string; str2: contained string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/
Function isLastMatch (str1, str2 ){
Var index = str1.lastIndexOf (str2 );
If (str1.length = index + str2.length) return true;
Return false;
}

More Character 1 ends with string 2

Character 1 contains string 2

 

/*
Purpose: character 1 is a string containing 2
Input: str1: string; str2: contained string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/
Function isMatch (str1, str2 ){
Var index = str1.indexOf (str2 );
If (index =-1) return false;
Return true;
}

More Character 1 contains string 2 Information

Email or not

 

/*
Purpose: Check whether the value of the input object complies with the E-Mail format.
Input: str string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/
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;
}

More email information?

Is it a mobile phone number?

 

/*
Purpose: Check whether the entered mobile phone number is correct.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/
Function checkMobile (s ){
Var regu =/^ [1] [0-9] [0-9] {9} $ /;
Var re = new RegExp (regu );
If (re. test (s ))....

Whether it is a mobile phone number or not

Digit or not

 

/*
Purpose: Check whether the input string is a number.
Input:
Str: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/

Function isNumber (str)
{
Var reg =/^ d + $ /;
If (reg. test (str ))...

Whether it is a number or not

Time or not

 

/*
Purpose: Check whether the input string conforms to the time format.
Input:
Time: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/
Function isTime (time ){
Var regex =/^ [0-2] {1} [0-9] {1}: [0-5] {1} [0-9] {1 }: [0-5] {1} [0-9] {1} $ /;
If (! Regex. test (time )){
Return false;
}....

More time information?

Is it a positive integer?

 

/*
Purpose: Check whether the input string conforms to the positive integer format.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/
Function isNumber (s ){
Var regu = ^ [0-9] + $;
Var re = new RegExp (regu );
If (s. search (re )! =-1 )...

More positive integer Information

Is it a phone number?

 

/*
Purpose: Check whether the input string meets the Chinese fixed-line or fax format.
Input:
S: string format, for example, 020-87110252
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/

Function isTel (s ){
Var reg =/^ (0d {2, 3 })-)? (D {7, 8}) (-(d {3 ,}))? $ /;
If (! Reg. test (s ))...

Whether the phone number is used

Port Number?

 

/*
Purpose: Check whether the value of the input object conforms to the port number format.
Input: str string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/
Function isPort (str ){
Return (isNumber (str) & str <65536 );
}

More port number information

ID number?

 

/*
Purpose: Check whether the input string meets the ID card format
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/

Function isIDno (strIDno)
{
Var aCity = {11: Beijing, 12: Tianjin, 13: Hebei, 14: Shanxi, 15: Inner Mongolia, 21: Liaoning, 22: Jilin, 23: Heilongjiang, 31: Shanghai, 32: Jiang ....

For more information, see ID card numbers.

Is it a zip code?

 

/*
Purpose: Check whether the input string conforms to the zip code format.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/

Function isZipcode (str)
{
Var reg =/^ d + $ /;
If (! Reg. test (str ))...

Is it a zip code?

Is it an amount?

 

/*
Purpose: Check whether the input string meets the amount format
The format is defined as a positive number with decimal places. A maximum of three decimal places can be entered.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/
Function isMoney (s ){
Var regu = ^ [0-9] + [.] [0-9] {0, 3} $;
Var re = new RegExp (regu );
If (re. test (s ))...

More information about whether it is an amount

Whether it is only Chinese Characters

 

/*
Purpose: Check whether the input string is composed of only Chinese characters.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/

Function isZh (str ){
Var reg =/^ [1-Snapshot] + $ /;
If (reg. test (str ))...

More Chinese character information?

Whether it is an integer

 

/*
Purpose: Check whether the value of the input object conforms to the integer format.
Input: str string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/
Function isInteger (str ){
Var regu =/^ [-] {0, 1} [0-9] {1,} $ /;
Return regu. test (str );
}

More integer Information

Verify IP Address

 

/*
Purpose: Verify the IP address format.
Input: strIP: IP Address
Return: If the verification succeeds, true is returned; otherwise, false is returned;
*/
Function isIP (strIP ){
If (isNull (strIP) return false;
Var re =/^ (d +). (d +) $/g // Regular Expression matching IP addresses
If (re. test (strIP )){
If (RegExp. $1

More IP address verification information

Chinese characters, letters, and numbers

 

/*
Purpose: Check whether the input string consists of only Chinese characters, letters, and numbers.
Input:
Value: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/
Function isChinaOrNumbOrLett (s) {// determines whether it is composed of Chinese characters, letters, and numbers.
Var regu = ^ [0-9a-zA-Z-region] + $;
Var re = new RegExp (regu );
If (re. test (s ))...

More Chinese characters, letters, and numbers

English numerals

 

/*
Purpose: Check whether the input string consists of only English letters and numbers.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/
Function isNumberOrLetter (s) {// determines whether it is a number or letter
Var regu = ^ [0-9a-zA-Z] + $;
Var re = new RegExp (regu );
If (re. test (s ))...

More English numbers

 

 

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.