Posted: 4/27/2011
Hello,
I want to validate the input in the textbox. a). Textbox should only take numeric values.
b). First character cannot be "0". If user enters "0" or "00" or "000" it should not be allowed.
c). Although "0" can be put after any number from "1" to "9".
Does anyone has a regex or javascript to achieve it?
Thanks,
Sumit
Posted: 4/28/2011
Demo: http://jsbin.com/ajipo5Code:
<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.5.2/jquery.min.js"></script> <script type="text/javascript"> $(function() { $('#<%= TextBox1.ClientID %>').keyup(function() { var filter = /^[1-9][0-9]*$/ var label = $('#<%= Label1.ClientID %>') if (filter.test(this.value)) { label.html('Valid'); } else { label.html('Invalid'); } }); }); </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </form> </body> </html>