简体   繁体   English

正则表达式匹配10-14位数

[英]Regular expression to match 10-14 digits

我使用正则表达式只匹配数字,最小10位数,最多14位。我试过:

^[0-9]

I'd give: 我给:

^\d{10,14}$

a shot. 一枪。

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: 我也想为那些不支持所有PCRE东西的RE引擎提供额外的解决方案,所以,在紧要关头,你可以使用:

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

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: 如果你的RE引擎是如此原始,甚至不允许特定的重复,你必须恢复到一些丑陋的黑客,如完全指定备用RE为10到14的数字位数,或者更容易,只是检查对于:

^[0-9]*$

and ensuring the length was between 10 and 14. 确保长度在10到14之间。

But that won't be needed for this case (ASP.NET). 但是这种情况不需要(ASP.NET)。

^\d{10,14}$

regular-expressions.info regular-expressions.info

  • Character Classes or Character Sets 字符类或字符集

    \\d is short for [0-9] \\d[0-9]缩写

  • Limiting Repetition 限制重复

    The syntax is {min,max} , where min is a positive integer number indicating the minimum number of matches, and max is an integer equal to or greater than min indicating the maximum number of matches. 语法为{min,max} ,其中min是表示最小匹配数的正整数, max是等于或大于min的整数,表示最大匹配数。


The limited repetition syntax also allows these: 有限的重复语法也允许这些:

^\d{10,}$ // match at least 10 digits
^\d{13}$  // match exactly 13 digits

try this 试试这个

@"^\d{10,14}$"

\\d - matches a character that is a digit \\ d - 匹配一个数字字符

This will help you 这会对你有所帮助

If I understand your question correctly, this should work: 如果我理解你的问题,这应该有效:

\d{10,14}   

Note: As noted in the other answer.. ^\\d{10,14}$ to match the entire input 注意:如另一个答案中所述.. ^\\d{10,14}$来匹配整个输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM