How to limit the number of digits before and after the decimal point in the keybox keypress event

advertisements

I have a Gridview with a textbox. How do I limit the number of digits before and after the decimal point in a textbox keypress event? I want a maximum of 6 digits before the decimal point and 2 digits after the decimal point. How do I do this with javascript/JQuery?


I personally do not like wiping out the data as soon as a user types something.

Instead, I like to display an error message after they finish entering data.

For example,

<asp:TextBox runat="server" ID="TextBox1" MaxLength="9" />
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1"
    ValidationExpression="^((\d{5})*|([1-9]\d{0,5}))(\.\d{0,2})?$"
    ControlToValidate="TextBox1" Text="Input must be 123456.78 format."
    Display="Dynamic" />