1

我们有一个实时项目,我需要使用正则表达式过滤掉任何电话号码中的字母。

活着,我不能摆弄它,所以我在想这个正则表达式:

^[^a-zA-Z]*$

你认为它会成功吗?消除包含字母的电话号码?

作为一个多元文化的网站,你知道有哪个国家在电话号码中使用字母吗?

干杯!

4

1 回答 1

3

Based on your current regex, I am assuming that you need a regex that will only match valid inputs.

Your current regex will work fine to prevent letters, but I think it would make more sense to figure out the minimum set of characters you consider valid and create a regex for that.

For example if you only want to allow digits you could use ^\d*$ or ^[0-9]*$.

To also allow spaces, hyphens, and parentheses so a number like (123) 456-7890 would be valid:

^[\d \-()]*$
于 2013-05-09T16:33:22.163 回答