Click here to Skip to main content
15,672,517 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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#

1 solution

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("negation");//if data not match

its working .
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900