正则表达式以匹配10-14位数字 [英] Regular expression to match 10-14 digits

查看:393
本文介绍了正则表达式以匹配10-14位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用正则表达式仅匹配数字,最少10个数字,最多14个.我尝试过:

I am using regular expressions for matching only digits, minimum 10 digits, maximum 14. I tried:

^[0-9]

推荐答案

我要给出:

^\d{10,14}$

一枪.

我还想为不支持所有PCRE内容的RE引擎提供额外的解决方案,因此,您可以在紧急情况下使用:

I also like to offer extra solutions for RE engines that don't support all that PCRE stuff so, in a pinch, you could use:

^[0-9]{10,14}$

如果您的RE引擎太原始了,甚至不允许特定的重复,那么您将不得不改用一些丑陋的技巧,例如用10到14个备用RE来完全指定位数,或者更容易,只需检查:

If you're RE engine is so primitive that it doesn't even allow specific repetitions, you'd have to revert to either some ugly hack like fully specifying the number of digits with alternate REs for 10 to 14 or, easier, just checking for:

^[0-9]*$

并确保长度在10到14之间.

and ensuring the length was between 10 and 14.

但是这种情况(ASP.NET)并不需要.

But that won't be needed for this case (ASP.NET).

这篇关于正则表达式以匹配10-14位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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