Regular Expression To Allow only 2 Decimal Places in the Textbox Control
Regular Expression To Allow only 2 Decimal Places in the Textbox Control :
In order to allow only 2 decimal places in the textbox use the regular expression validator. In the validator control there will be a property called ValidationExpression,use this property to assign the valid expression as shown below.
<asp:TextBox ID=”_tbCost” runat=”server” TabIndex=”4″></asp:TextBox>
<asp:RegularExpressionValidator ID=”_ReqExpressionPhoneNo” runat=”server” ErrorMessage=”Enter numbers & ‘.’ only,should contain only 2 decimal places.” ControlToValidate=”_tbCost” Display=”none” ValidationExpression=”(?!^0*$)(?!^0*\.0*$)^\d{1,18}(\.\d{1,2})?$”>
</asp:RegularExpressionValidator>
This is the expression that allows only 2 decimal places
ValidationExpression=”(?!^0*$)(?!^0*\.0*$)^\d{1,18}(\.\d{1,2})?$”
And also for more information on regular expressions see the below link:
Also look at: http://regexlib.com/Search.aspx?k=decimal&c=-1&m=-1&ps=20
Happy Coding……………
No comments
No comments yet. Be the first.
Leave a reply
