我使用的技术从这个链接来掩盖我的文本框接受以十进制格式(数字与一个周期)的字符串。
I am using the technique from this link to mask my textbox to accept strings that are in decimal-format (Digits with a single period).
如何定义文本框输入限制?
下面是我把面具正则表达式:
Here is the regex I put in the mask:
b:Masking.Mask="^\d+(\.\d{1,2})?$"
有关一些奇怪的原因,它让我输入的数字,但我不能插入期间在我的文本框。
For some odd reason, it lets me input the digits but I cannot insert the period in my textbox.
我也验证了正则表达式在这里,所以正则表达式是绝对正确的。
I've also validated the regex here so regex is definitely correct.
的http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-ex$p$pssion-tester.ashx
可能是什么问题?
修改您的正则表达式这一点:
Modify your regex with this:
^\d+([\.\d].{1,2})?$
演示
DEMO
编辑:
以上的正则表达式也将让 123..1
即超过1小数点。所以我只是发现了这个问题,并固定在下面的一个:
The above regex will also allow 123..1
that is more than 1 decimal point. so I just found the problem and fixed with the below one:
^(\d+)?+([\.]{1})?+([\d]{1,2})?$
演示
DEMO
上一篇:与ReferenceLoopHandling.Ignore连载循环依赖ISerializable的对象时StackOverflowException被抛出抛出、对象、Ignore、ReferenceL