Here is an example where we require a 4 digit number - nothing else is acceptable: The only new attribute we use, is the validationexpression.
This attribute simply holds the Regular Expression which should be used to validate the field.
a are valid date values and if so, they will be converted into a machine readable format.
Afterwards these two values are compared with the compare validator.
You can use them to constrain input, apply formatting rules, and check lengths. This How To shows how you can use regular expressions within ASP. Objectives Overview Using a Regular Expression Validator Control Using the Regex Class Common Regular Expressions Additional Resources If you make unfounded assumptions about the type, length, format, or range of input, your application is unlikely to be robust.
To validate input captured with server controls, you can use the Regular Expression Validator control. Input validation can become a security issue if an attacker discovers that you have made unfounded assumptions.
The Regular Expression Validator is a bit more difficult to write about, because it requires knowledge of Regular Expressions to really use it.
However, Regular Expression Validator is one of the most useful validators, because it can be used to check the validity of any kind of string.
In this case we need to check to see if the user has entered a number into a text box called TXT_Number after clicking a button named Button1.Try switching to Design view and select the Regular Expression Validator on your page.Now have a look in the Properties tab of Visual Studio. This article will explain how to make sure that the user only submits a number to your .NET web application and also demonstrate how to add Java Script to your ASPX pages.This content is outdated and is no longer being maintained.