Common JavaScript form verification set
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 );
}
}
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.