tags:

views:

43

answers:

3

I have a div tag that contains a textbox and a submit button. I am trying to only have the submit button work if the text entered is a number (int or decimal). However when running the debugger, the onclick function is called no matter what text is entered. Any idea how I messed this up?

<div class="content">
<table class="inputForm">
  <tr>
   <th>Percentage:</th>
  <td>
   <asp:TextBox ID="VATAmount" runat="server"></asp:TextBox>
  </td>
  <td>
   <asp:LinkButton ID="VATSubmit" runat="server" SkinID="Button" OnClick="VAT_Click" Text="Submit"></asp:LinkButton>
  </td>
 </tr>
</table>
<i>50% should be entered as 50</i>                                    
  <cb:RequiredRegularExpressionValidator ID="VATVerify" runat="server" ControlToValidate="VATAmount" 
Display="Static" ErrorMessage="The Percent should be written as a decimal." Text="*" ValidationGroup="Add"
ValidationExpression="[*0-9]*\.[*0-9]" Required="true">
  </cb:RequiredRegularExpressionValidator>

Also I should note that the * does appear when an incorrect value is entered, but not when a correct one is entered

A: 

It seems that the regular expression might not be correct. The following might work (I say might because regex patterns are always sneaky in their ways of failing):

^[0-9]*\.?[0-9]+$
Mark Wilkins
Still doing the same thing
0_o
A: 

Try something like this:

^[0-9]+(?:\.[0-9]+)?$
LukeH
Still no change. :(
0_o
A: 

The original poster's provided regex is definitely wrong, but I'm not sure that's the true cause. The one provided by @Mark Wilkins works great.

My guess would be that your validation isn't firing at all. You might try setting the CausesValidation="True" for your LinkButton and see if that helps.

Aaron D
@Mark Wilkins regex does work great! I tried putting CausesValidation="True" in the code, but still the behavior is the same.
0_o