如何在C#中编写正则表达式来检查在文本框中输入的任何内容,除了十进制前最多两位数,后跟小数点和十进制后一位数(即如何使用...

问题描述:



我有一个接受小时的文本框。它只接受数字和十进制值。

它将允许小数点前最多两位数,后跟一个小数点,然后只有一个小数点。



现在使用下面的正则表达式:



正则表达式ToValidate_String_Structure =新的正则表达式(^ \\d {1,2} ([。] \\\\ {1})$);





所以我现在如何使用否定上面的表达式检查除了上面的正则表达式格式之外在文本框中输入的内容吗?





请帮助我..我想要一个解决方案在C#

Hi,
I have an text box which accepts hours. It will accept only numeric and decimal values.
And it will allow max of two digits before the decimal point, followed by a decimal point and then only single decimal point.

so now using the below regular expression:

Regex expressionToValidate_String_Structure = new Regex("^\\d{1,2}([.]\\d{1})$");


so now how can i use negation in the above expression to check anything entered in the text box apart from the above regular expression format?


please help me.. i want a solution in C#

);





所以现在怎么样我可以在上面的表达式中使用否定来检查除上述正则表达式格式之外在文本框中输入的内容吗?





请帮助我...我想要一个C#的解决方案
");


so now how can i use negation in the above expression to check anything entered in the text box apart from the above regular expression format?


please help me.. i want a solution in C#


我在规则中做了一些小改动表达式,





正则表达式r1 =新正则表达式(@^(?< data_0> [0-9] {1, 2})。(?< data_1> [0-9] {1})
I make small change in regular expression,


Regex r1 = new Regex(@"^(?<data_0>[0-9]{1,2}).(?<data_1>[0-9]{1})


);

if(!(r1.IsMatch(textBox1) .Text)))

{

MessageBox.Show(否定); //如果数据不匹配

}





工作。

:)
");
if (!(r1.IsMatch(textBox1.Text)))
{
MessageBox.Show("negation");//if data not match
}


its working .
:)