3

I am using the "New" number textbox mode that is available for sites running .NET 4.5 and I am attempting to validate user input with the asp.net validation controls. I am able to validate that the number chosen falls within a specified range (1-254) with the following REGEX expression:

^([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|2[5][0-6])$

This expression should also validate that the input is of numeric value and does not contain characters. For some reason the validation for the range works appropriately, but if I input "A" or any other character string it will return as valid.

If I remove the TextMode="Number" property from the textbox everything works as it should. Has anyone else run across this bug?

If I access the site in an older browser which ignores the new textbox textmode, validation works appropriately.

5
  • 1
    Don't use regex to validate number in a range. It is very unreadable. Commented Sep 17, 2013 at 18:50
  • Have you tried range validator instead? Commented Sep 17, 2013 at 19:40
  • I used the range validator but ran into the same issue where it would not invalidate letters. I thought that by switching to REGEX it might fix the issue, but it does not seem to be the case. I could absolutely switch back to range validators but it would leave me with the same issue. Commented Sep 19, 2013 at 14:56
  • can you not validate that it is a number AND validate that it is in range? Two validators on one input is possible yeah? In the past, for example, I'd have to validate with a 'required' and a regex validator when validating emails. Commented Oct 10, 2013 at 15:54
  • This may be an option, I think for now I just stuck with using the old textbox modes because the new modes are not supported by all browsers. Commented Oct 11, 2013 at 17:38

1 Answer 1

0

It sounds like you want two validators for this textbox, one, that the entered value is a number (comparevalidator with operator set to data type check and type set to integer), and one that the number is within a given range (rangevalidator with appropriate min/max values).

Is there a reason that you need to combine both checks in a single validator?

Sign up to request clarification or add additional context in comments.

1 Comment

I don't believe setting the textbox mode to "Number" causes validation. It simply extends the box with arrows to increment/decrement the value. You can still type in a letter or other symbol if you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.