This article describes the JS and jquery verified e-mail, mobile phone number, zip code method.
jquery Code:
Verify ZIP code
$ ("#postcode"). blur (function () {
//Get Postal code
var postcode=$ ("#postcode"). Val ();
if (Is_postcode (postcode)) {
$ ("#postcode_info"). HTML ("");
else{
$ ("#postcode_info"). HTML ("Incorrect postal code format");
return false;
}
});
Verify the phone number
$ ("#mobile"). blur (function () {
//Get cell phone number, and remove the left and right sides of the space
var mobile=$.trim ("#mobile"). Val ());
if (Is_mobile (mobile)) {
$ ("#mobile_info"). HTML ("");
else{
$ ("#mobile_info"). HTML ("Incorrect cell phone number format");
return false;
}
});
Verify email
$ ("#email"). blur (function () {
//Get email
var email=$ ("#email"). Val ();
if (is_email (email)) {
$ ("#email_info"). HTML ("");
else{
$ ("#email_info"). HTML ("Incorrect e-mail format");
return false;}});
JS Code:
Order Submission page-Verify ZIP code
function Is_postcode (postcode) {
if (postcode = "") {return
false;
} else {
if (!/^[0-9][0-9]{5}$/.test (postcode)) {return
false;
}
}}
return true;
}
Order Submission Page-Verify phone number
function Is_mobile (MOBILE) {
if (mobile = "") {return
false;
} else {
if (!/^0{0,1} (13[0-9]|15[0-9]|18[0-9]|14[0-9]) [0-9]{8}$/.test (MOBILE)) {return
false;
}
return true;
}
Order Submission Page-Verify the legality of the email
function is_email (email) {
if (email = = "") {return
false;
} else {
if (!/^[\w\-\.] +@[\w\-\.] + (\.\w+) +$/.test (email)) {return
false;
}
}
return true;
}
PS: Here again for you to provide 2 very convenient regular expression tools for your reference to use:
JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript
Regular expression online generation tool:
Http://tools.jb51.net/regex/create_reg
I hope this article will help you with JavaScript programming.