user3253718
user3253718

Reputation:

Regular Expression Validation error does not show up on entering a whitespace

I have written a regular expression to allow maximum 3 decimal digits. The Regex is:

^\d+([.,]\d{1,3})?$

It works perfectly for correct inputs such as (100,100.22 etc) and also shows up the validation error when the user tries to input (0. or , or 10.11111)

However, the error does not get displayed when I am trying to enter spaces. The form doesn't get submitted. There is no way for a user to understand what is causing the error.

Following is my code in aspx file:

<td>
<asp:TextBox ID="txtBuildingSize" CssClass="textbox" runat="server" 
 ToolTip="in Sq Ft" meta:resourcekey="txtBuildingSizeResource1"></asp:TextBox>
<asp:Label ID="lblSqM1" runat="server" CssClass="optionLabel" 
meta:resourcekey="lblSqM1Resource1" Text="square meters"></asp:Label>
</td>
<td>
<asp:RegularExpressionValidator ID="strBuildingSizeValidator" 
  ControlToValidate="txtBuildingSize" Display="Dynamic"
  runat="server" ForeColor="Red" ValidationExpression="^\d+([.,]\d{1,3})?$" 
  meta:resourcekey="strBuildingSizeValidatorResource1" 
  Text="* Max 3 decimals only"></asp:RegularExpressionValidator>

What could be the problem?


Solved: ^\d+([.,]\d{1,3}\ {0,0})?$


The (space){0,0} did the trick. The error message shows up.

Upvotes: 2

Views: 419

Answers (1)

Stephan
Stephan

Reputation: 43033

Solution found by Manasi:

^\d+([.,]\d{1,3}\ {0,0})?$

Description

Regular expression visualization

Upvotes: 1

Related Questions