JavaScript form Common validation set _javascript tips

Source: Internet
Author: User
JavaScript form authentication Age
JavaScript form validation age, to determine whether an input is in line with age, implemented through regular expressions.
Check 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 Validation mailbox
JavaScript form verification Email to determine whether an input amount is a mailbox email, implemented through regular expressions.
Check email Email
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 validation Chinese capital letters
JavaScript forms validate Chinese capital letters to determine whether an input is an English letter in Chinese or uppercase, and is implemented through regular expressions.

Check whether it is a valid real name and can only contain Chinese or uppercase letters in English.
function Isvalidtruename (strName) {
var str = Trim (strName); To determine whether it is all English or Chinese, you can include spaces
var reg =/^[a-z u4e00-u9fa5]+$/;
if (Reg.test (str)) {
return false;
}
return true;
}
JavaScript form validation is Chinese
JavaScript form validation is Chinese, determines whether an input is Chinese and is implemented through regular expressions.

Check to see if it is Chinese
function Ischn (str) {
var reg =/^[u4e00-u9fa5]+$/;
if (!reg.test (str)) {
return false;
}
return true;
}
JavaScript form authentication phone number
The JavaScript form verifies the phone number to determine whether an input is a phone number and is implemented through a regular expression.
Check phone number
function Istel (str) {
var reg=/^ ([0-9]|[ \-]) +$/g;
if (str.length<7 | | str.length>18) {
return false;
}
else{
return reg.exec (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.