Common JavaScript form verification set

Source: Internet
Author: User

Javascript Form Verification age
The javascript form verifies the age and determines whether an input value conforms to the age by using a regular expression.
// Check the age
Function isage (STR ){
VaR mydate = new date;
VaR now = mydate. getfullyear ();
If (STR <now-60 | STR> now-18 ){
Return false;
}
Return true;
}
Regular Expression verification email
The javascript form verifies the email and determines whether an input is an email address using a regular expression.
// Check the email address
Function isemail (STR ){
VaR Reg =/^ ([a-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + ((\. [a-zA-Z0-9 _-] {2, 3}) {1, 2}) $ /;
Return Reg. Test (STR );
}

Javascript Form Verification uppercase letters
The javascript form verifies Chinese uppercase letters and determines whether an input is a Chinese or uppercase English letter, which is implemented through a regular expression.

// Check whether the name is a valid real name. It can only contain Chinese or uppercase English letters.
Function isvalidtruename (strname ){
VaR STR = trim (strname); // determines whether it is in uppercase or in Chinese. It can contain spaces.
VaR Reg =/^ [A-Z u4E00-u9FA5] + $ /;
If (Reg. Test (STR )){
Return false;
}
Return true;
}
Javascript Form Verification for Chinese
The javascript form verifies whether the input value is Chinese and whether the input value is Chinese. It is implemented through a regular expression.

// Check for Chinese Characters
Function ischn (STR ){
VaR Reg =/^ [u4E00-u9FA5] + $ /;
If (! Reg. Test (STR )){
Return false;
}
Return true;
}
Javascript Form Verification phone number
The javascript form verifies the phone number and determines whether the input is a phone number. This is implemented using a regular expression.
// Check the phone number
Function istel (STR ){
VaR Reg =/^ ([0-9] | [\-]) + $/g;
If (Str. Length <7 | Str. length> 18 ){
Return false;
}
Else {
Return reg.exe C (STR );
}
}

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.