Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex validator allowing empty as an input

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)." />
like image 812
Blankman Avatar asked Apr 22 '09 16:04

Blankman


People also ask

Is the empty string a regular expression?

ε, 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.

Is regex input validation?

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.

How do you validate expressions in regex?

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.

What is regex validator control?

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.


1 Answers

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.

like image 169
bdukes Avatar answered Oct 18 '22 13:10

bdukes