Javascript Regex - 用于验证电话号码的用途? [英] Javascript Regex - What to use to validate a phone number?

查看:125
本文介绍了Javascript Regex - 用于验证电话号码的用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉我RegEx将用于验证国际电话号码,包括号码之间的空白区域以及允许这些字符: - ()

Could anyone tell me what RegEx would work to validate an international phone number including white space between the numbers and also allowing for these chars: - ( ).

字符串中的数字量不是太重要,我希望用户能够输入类似示例1或2的内容,如果他们愿意的话:

The amount of numbers in the string is not too important, I would just like the user to be able to type something like either example 1 or 2 if they wish:

示例:


  1. +44(0)207 111 1111

442071111111

我已经阅读并根据我的理解测试了一些类似问题的答案,但到目前为止,他们都没有按照我的方式为我工作我希望他们这样做。

I have already read through and tested the posted answers to some similar questions to the best of my understanding but so far none of them are working for me the way I want them to.

请有人帮我解释一下上面应该如何编写以供验证吗?

Please can someone help me out with a clear explanation of how the above should be written for validation?

非常感谢任何可以提供帮助的人。

Many thanks to anyone who can help.

推荐答案

try this 
 $("#phone").blur(function () {
            var regexp = /^[\s()+-]*([0-9][\s()+-]*){6,20}$/
            var no = $("#phone").val();
            if (!regexp.test(no)&& no.length<0) {
                alert("Wrong phone no");
            }

        });

<input type="text" id="phone"/>

这篇关于Javascript Regex - 用于验证电话号码的用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆