KALEEM says:
I need a vliadation for textbox
Codition is Either I can fill 7 numeric digit oR left null text box
|
1
2
3
|
<asp:TextBox runat="server" ID="txtmail" type="enroll" value="" placeholder="enroll"></asp:TextBox>
<asp:Button runat="server" ID="btnsubmit" type="submit" Text="Submit" value="Submit" />
|
Please help me.
Thanks
Hi Kaleem,
Validating the textbox value whether it is numeric or not on button click event is a bit lengthy process. Instead of validating textbox value on button click, better you only allow user to enter the numeric value (ie 0 to 9) and by setting the MaxLength property of textbox you can control the input length.
Just put this inside your textbox control properties.
MaxLength="7" onkeypress="return onlyNumbers(this)"
and add below javascript code in your head section.
function onlyNumbers(evt) {
var e = event || evt;
var charCode = e.which || e.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
And one more thing, always try to validate your data on client side only.
Hope it will help you.