Shouldn't this regex validator make sure the user enters something in the textbox? For some reason an empty textbox passes through.
<asp:RegularExpressionValidator ID="revNumericValidator" runat="server" ValidationExpression="^\d+$"
ControlToValidate="tb1" ErrorMessage="Please enter blah (must be a number)." />
ε, the empty string, is a regular expression. Here ε represents the language made up of the empty string {ε}. 3. ∅, the empty set, is a regular expression.
Regular expressions describe patterns that match combinations of characters in strings. They have a variety of applications, such as validating user input from HTML forms. You can use regex to validate with JavaScript or via the HTML pattern attribute.
When you create a text question, along with word/character limits, you can validate for Regex pattern matching. To validate a field with a Regex pattern, click the Must match pattern check box.
The RegularExpressionValidator control checks whether the value of an input control matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in email addresses, telephone numbers, and postal codes.
Validators by convention don't validate empty text. If you want to require a value, you have to also add a RequiredFieldValidator.
MSDN says
Validation succeeds if the input control is empty. If a value is required for the associated input control, use a RequiredFieldValidator control in addition to the RegularExpressionValidator control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With