I need validation on Rate like example
1-True
1.00-True
1.56-True
Means I need numeric values + point only
Validate two Decimal numbers with two decimal places using RegularExpression in JavaScript and jQuery
Hi amar,
Refer below sample code.
Javascript
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function ValidateDecimal(ele) { //var regex = /^\d+(\.\d{1,2})?$/; var regex = /(?:\d*\.\d{1,2}|\d+)$/; if (regex.test(ele.value)) { alert("Valid"); } else { alert("Invalid"); } } </script> </head> <body> <form id="form1" runat="server"> <div> <input name="txtText" type="text" id="txtText" onblur="return ValidateDecimal(this);" /> </div> </form> </body> </html>
Demo
jQuery
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("#txtText").on("blur", function () { //var regex = /^\d+(\.\d{1,2})?$/; var regex = /(?:\d*\.\d{1,2}|\d+)$/; if (regex.test($(this).val())) { alert("Valid"); } else { alert("Invalid"); } }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input name="txtText" type="text" id="txtText" /> </div> </form> </body> </html>
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.