admin管理员组

文章数量:1335614

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.

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.

Share Improve this question asked Aug 23, 2016 at 4:59 User123User123 2893 silver badges17 bronze badges 4
  • see this stackoverflow./questions/4338267/… – Hadi Commented Aug 23, 2016 at 5: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. – Chris Commented Aug 23, 2016 at 5:03
  • Apparently you also want optional separators between parts. Try Google. – RobG Commented Aug 23, 2016 at 5:53
  • refer this stackoverflow./a/12858073/5292301 – User Commented Aug 23, 2016 at 6:08
Add a ment  | 

1 Answer 1

Reset to default 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>

本文标签: javascriptCountry code validationStack Overflow