Hi Team ,
I have a textbox which should accept only 0 or 100 in it.
Please suggest regular expression for this.
I have tried regular one but that expects numbers between 0-9.
Hi Waghmare,
Refer below code.
HTML
<html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <style type="text/css"> .error { color: red; } </style> </head> <body> <input type="text" id="txtNumber" /> <br /> <span id="lblError" style="color: red"></span> <br /> <br /> <input type="button" id="btnValidate" value="Submit" onclick="ValidateNumber()" /> <script type="text/javascript"> function ValidateNumber() { var number = document.getElementById("txtNumber").value; var lblError = document.getElementById("lblError"); lblError.innerHTML = ""; var expr = /^([0]|100)$/; if (!expr.test(number)) { lblError.innerHTML = "Only 0 or 100 allowed."; } } </script> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.