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
1 Answer
Reset to default 6try 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
版权声明:本文标题:javascript - Country code validation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742391824a2466139.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论