如何在C#中的文本框中对正则表达式使用否定 [英] How to use negation for a regular expression in textbox in C#
本文介绍了如何在C#中的文本框中对正则表达式使用否定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个接受小时的文本框。文本框仅接受数字和小数值。
使用以下正则表达式
正则表达式ToValidate_String_Structure =新的正则表达式(^ \\d {1,2}([。] \\\\ {1})$);
所以现在我如何在上面的正则表达式中使用否定来检查除上述表达式之外在文本框中输入的内容?
请在C#中为我提供了一个解决方案?
Hi,
I have an text box which accepts hours. The text box accepts only numeric and decimal values.
am using the following regular expression
Regex expressionToValidate_String_Structure = new Regex("^\\d{1,2}([.]\\d{1})$");
So now how can i use negation in the above regular expression to check anything entered in the text box apart from the above expression?
Please provide me a solution in C#?
推荐答案
);
所以我现在如何使用否定在上面的正则表达式中检查除上述表达式之外在文本框中输入的内容?
请在C#中为我提供解决方案?
");
So now how can i use negation in the above regular expression to check anything entered in the text box apart from the above expression?
Please provide me a solution in C#?
如果您使用的是HTML5:
< input type =" text" name =" name" pattern =" [0-9]" title =" title" />
否则你需要Java脚本。
If you are using HTML5:
<input type="text" name="name" pattern="[0-9]" title="title" />
Otherwise you will need JavaScript.
参见 MSDN:使用正则表达式验证文本框 [ ^ ]。
即你可以实现一个离开文本框事件处理程序并用那里的任何方式触发检查。
如果你使用Regex,你可以询问Success
属性。否定是你希望一个模式导致match.Success == false
。
干杯>
Andi
See MSDN: Validate Textbox with Regular Expressions[^].
I.e. you may implement a leave text box event handler and trigger the check with whatever means there.
If you use Regex, you can ask theSuccess
property. Negation is if you expect a pattern to result inmatch.Success == false
.
Cheers
Andi
这篇关于如何在C#中的文本框中对正则表达式使用否定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文