A regular expression to check for a number with 2 decimals looks like this
"^(\+|-)?\d{1,6}(\.\d{1,2})?$". You may use it in a
RegularExpressionValidator:
<asp:TextBox ID="txtNumber" Runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="valTxtNumber"
ControlToValidate="txtNumber" Runat="Server" ValidationExpression
="^(\+|-)?\d{1,6}(\.\d{1,2})?$" ErrorMessage="Number is not valid. Please
enter numbers with 2 decimals only" > </asp:RegularExpressionValidator>
Or you may use it in a Javascript like this:
var re = /^(\+|-)?\d{1,6}(\.\d{1,2})?$/g;
alert(re.test("123456.123")); //this will echo false
alert(re.test("56.23")); //this will echo true
--
HTH,
Phillip Williams
http://www.societopia.net http://www.webswapp.com
"NH" wrote:
How can I check the value of a textbox has no more than 2 decimal places?
I already check that the value is numeric, but how do I check that it is not
0.223 or .022 etc. I only want to allow up to 2 decimal places...