JS phone number verification is a more common type of verification,A small example of a javascript verification phone number is given below.Domestic fixed telephones are composed of seven or eight digits.May also carry the long-distance area code.

General home phone number,If the area code is not 7 or 8 digits long,The area code is 3 or 4 digits and a horizontal line.So, we are writing the verification code to verify the phone number through two regular expressions.

<html xmlns="http://www.w3.org/1999/xhtml">
  <title>phone number verification</title>
  <script type="text/javascript">
    function checktel () {
      var obj=document.getelementbyid ("txttel");
      var value=obj.value;
      var regtel1 =/^ (([0 \ +] \ d {2,3}-)?(0 \ d {2,3})-) (\ d {7,8}) (-(\ d {3,}))?$/. test (value);//landline phone with area code
      var regtel2=/^(\d{7,8})(-(\d{3,}))?$/.test(value);//fixed telephone without area code
      if (value!="") {
        if (! regtel1&&! regtel2) {
          alert ("Wrong phone number entered!");
          obj.focus ();
          return false;
      else {
        alert ("Please enter a phone number!");
        return false;
      alert ("The phone number is entered correctly!");
      return true;
  Please enter your phone number:
  <input type="text" />
  <input type="button" value="validation" onclick="return checktel ();" />

Home phone number js verification:

  • Previous WIFI master key password query interface example
  • Next PHP implements depth-first and breadth-first traversal methods for binary trees