如何创建正则表达式以仅接受1-14位数字? [英] How do I create a regular expression to accept 1-14 digits only?

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

问题描述

我知道当我看到答案时我会踢自己,但是我已经玩了一个小时并且无法弄清楚如何编写正则表达式以接受单行中的1-14位数字字符串并拒绝任何其他内容这是在WPF ValidationRule 中使用。



请注意,这不是试图找到这样的子字符串在一个文本体中;它旨在拒绝任何不适合的模式,所以 01234567890123 是好的,但 01234567890123X 是不。



我的尝试:



这些都不起作用:



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



[0-9] {1,14} $



^ [0-9] {1,14}



[0-9] {1,14}



这几乎可行......



\b [0-9] {1,14} \ b



.. 。但由于某种原因,将接受一个开放的支架,所以它将匹配的 1234(中,它应该拒绝。

解决方案




[0-9] {1,14}






^ [0-9] {1,14}



[0 -9] {1,14}



这几乎可以工作......



\b [0-9] {1,14} \ b



...但出于某种原因会接受一个打开括号,所以它将匹配 1234(,它应该拒绝。


引用:
^ [0-9] {1,14}

I know I am going to kick myself when I see the answer, but I have been playing with this for an hour and can't figure out how to write a regular expression to accept 1-14 digits in a single-line string and reject anything else. This is for use inside a WPF ValidationRule.

Note that this is not attempting to find such sub-strings in a body of text; it is intended to reject anything that does not fit the pattern, so 01234567890123 is fine but 01234567890123X is not.

What I have tried:

None of these work:

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

[0-9]{1,14}$

^[0-9]{1,14}

[0-9]{1,14}

This almost works...

\b[0-9]{1,14}\b

...but for some reason will accept an open bracket, so it will match 1234(, which it should reject.

解决方案



[0-9]{1,14}




^[0-9]{1,14}

[0-9]{1,14}

This almost works...

\b[0-9]{1,14}\b

...but for some reason will accept an open bracket, so it will match 1234(, which it should reject.


Quote:

^[0-9]{1,14}


这篇关于如何创建正则表达式以仅接受1-14位数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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