1

I am working on a form validation and I need to validate phone number with or without country code. Example: +1-555-532-3455, 555-555-5555, +919965425422.

Can any one suggest me how to achieve it with regular expression.

User123
  • 289
  • 3
  • 17
  • see this http://stackoverflow.com/questions/4338267/validate-phone-number-with-javascript – Hadi J Aug 23 '16 at 05:01
  • Please edit your question to include what you've tried, and the expected output(if any). Most users are more than happy to provide code for a coder in distress, but Stack Overflow is not a code writing service. – Christian Dean Aug 23 '16 at 05:03
  • Apparently you also want optional separators between parts. Try [*Google*](https://www.google.com.au/search?client=safari&rls=en&q=regular+expression+validate+phone+number&ie=UTF-8&oe=UTF-8&gfe_rd=cr&ei=PeS7V_fJNtLr8AfU3oJw). – RobG Aug 23 '16 at 05:53
  • refer this http://stackoverflow.com/a/12858073/5292301 – User Aug 23 '16 at 06:08

1 Answers1

6

try like this

<script type="text/javascript">  
    var reg = "(?:\s+|)((0|(?:(\+|)91))(?:\s|-)*(?:(?:\d(?:\s|-)*\d{9})|(?:\d{2}(?:\s|-)*\d{8})|(?:\d{3}(?:\s|-)*\d{7}))|\d{10})(?:\s+|)"; 

    function PhoneValidation(phoneNumber)
    {  
          var OK = reg.match(phoneNumber);  
          if (!OK) {
              window.alert("phone number isn't  valid");  
          }else{  
              window.alert("phone number is  valid");  
          } 
    }  
</script>
Shakir Ahamed
  • 1,290
  • 3
  • 16
  • 39