正则表达式(可选)允许使用括号,点,破折号,空格和加号输入电话号码 [英] regex optionally allowed parentheses, dots, dashes, spaces, and plus sign in phone number

查看:78
本文介绍了正则表达式(可选)允许使用括号,点,破折号,空格和加号输入电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证电话号码的值,我有此regEx /^\d+(-\d+)*$/允许在数字之间使用破折号.我在这里找到它,但是我忘记了链接.并且我尝试将其编辑为可选的括号,点,破折号,空格和加号,但是我是个初学者,因此暂时无法执行此操作.并且请注意,用户可以自由使用自己喜欢的格式,它只是允许他们输入破折号,空格,加号,点和括号.

I'm trying to validate the phone number value, I have this regEx /^\d+(-\d+)*$/ allowing a number with dashes in between of numbers. I find it here, but I forgot the link. And I try to edit it to optionally allowed parentheses, dots, dashes, spaces, and plus sign but I'm a beginner so that for now I can't do this to work. And please note that the user is free what format they are like to use, it simply allow them to input either dashes, space, plus sign, dots, and parentheses.

允许的值:

  • 0123456789
  • 012-345-6789
  • 012-345-6789
  • (012)-345-6789
  • (012)345-6789
  • +0123456789
  • + 012-345-6789
  • +(012)-345-6789

请有人帮帮我.

推荐答案

[0-9\-\(\)\+\s]+

您可以使用它来检查和/或使用正则表达式替换来删除所有这些字符并验证结果.

You can use that to check and/or use a regex replace to remove all those characters and validate the result.

要进行替换,您可能需要:[^0-9]

For replacement, you might want: [^0-9]

这篇关于正则表达式(可选)允许使用括号,点,破折号,空格和加号输入电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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