jquery verifies that the phone number complies with the rules and sets the submit button to a different state according to the cell phone number test results _jquery

Source: Internet
Author: User

Project requirements:

Enter the phone number, real-time judge the phone number entered the compliance with the rules:

If not, the Submit button is disabled, the mobile phone number information is not submitted, and the button displays a gray background;

If the rule is met, you can submit the phone number information you entered and set the button background to red.

The code is as follows:

<! 
  DOCTYPE html>  

Effect:

User input phone number is irregular:

When the user enters the phone number that matches the rule:

Ps:jquery Authentication Phone Number

var ismobile=/^ (?: 13\d|15\d|18\d) \d{5} (\d{3}|\*{3}) $/; Mobile phone number validation rule
var isphone=/^ ((0\d{2,3})-)? ( \d{7,8}) (-(\d{3,}))? $/;  Landline validation Rule
var Dianhua = $ ("#dianhua"). Val ();          Get the number value assigned by the user to the variable Dianhua
if (! Ismobile.test (Dianhua) &&!isphone.test (Dianhua) {//If the user enters a value that does not meet both the phone number and the landline number
  ("Please fill in the phone number correctly, for example : 13415764179 or 0321-4816048 "); Pop-up message
  $ ("#dianhua"). focus ();    The input box gets the cursor return
  false;     Returns an error, not executing down

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.