JS and jquery verified email, cell phone number, zip code method _javascript Skills

Source: Internet
Author: User

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.

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.