问题描述
我使用 ASP.NET普通防爆pression验证
来验证文本
。
有效样本:
11.111.111.120.1
0.12
无效的样本:
01.123
正如你所看到的,我不想输入只包含 0
。
目前我有这个前pression这是允许 0
。
^ [0-9] {1,2}([/] [0-9] {1,2})$?
我能做些什么,以prevent一个0?
任何帮助很多AP preciated。
这是如何工作的吗?
((?=。* [1-9])\\ D +(\\。\\ D +)?)
释解:
(= * [1-9]。) - 的比赛,但不包括任何大于1
\\ D +
- 匹配任何数字
(\\ \\ D +)。
- ?匹配一个小数点加上其余
忽略第二个分组,这仅仅是打破了正则表达式
I am using ASP.NET Regular Expression Validator
to validate a textbox
.
Valid Samples:
1
1.1
11.1
11.12
0.1
0.12
Invalid Samples:
0
1.123
As you can see I don't want the input to contain only 0
.
Currently I have this expression which is allowing 0
.
^[0-9]{1,2}([/.][0-9]{1,2})?$
What can I do to prevent a single 0?
Any help is much appreciated.
How does this work for you?
((?=.*[1-9])\d+(\.\d+)?)
Explaination:
(?=.*[1-9])
- Matches but excludes anything greater than 1
\d+
- Matches any digit
(\.\d+)?
- Matches a decimal point plus the remainder.
Ignore the second grouping, this is just to break the regex up.
这篇关于普通防爆pression接受小数而不单0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!