-1

I'm working on a project and i want verify users phone number on my website,but all i found is validate 10 digit phone number,so am confuse because in my country here in nigeria we use 11 digit as our phone number so how can i verify that also.

 function phonenumber(inputtxt)  
    {  
      var phoneno = /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;  
      if((inputtxt.value.match(phoneno))  
            {  
          return true;  
            }  
          else  
            {  
            alert("message");  
            return false;  
            }  
    }  

the code above is only for 10 digit how can i make it for 11 or is their any other way.

alertme
  • 61
  • 7
  • see this: https://stackoverflow.com/questions/4338267/validate-phone-number-with-javascript – SeanPlusPlus Sep 27 '17 at 20:48
  • i know their is a way because when i registered on facebook i used my 11 digit number and they verified it and notify me that is exactly what i want now but just the verification. – alertme Sep 27 '17 at 20:51

1 Answers1

1

According to your code the current format which can be validated is 'xx-xxxx-xxxx'

If you need to allow user enter the 11 symbols number you need to slightly change current regexp in this way:

var phoneno = /^\+?([0-9]{3})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/; 

It will now allow the 'xxx-xxxx-xxxx' format. (pay attention to the dashes position it is important in this case).

Artem Arkhipov
  • 7,025
  • 5
  • 30
  • 52