I want to restrict the user that he cant enter more than 6 characters in a text box.As a user start entering in the text box and reach to the max limit and try entering 7th character, the text box will not allow him to do so and alert him that max size reached.How i achieve this?
I had added JavaScript function in my code to do so but not getting that on which event i call this function , currently i am calling on on-blur but i m able to type more than 9 character in the text box and after that when i m clicking on a button then i m getting alert message.i want that while typing in the text box itself if max limit reached the user get prompted.My Current code is as follow:-
<asp:TextBox ID="txtVolumeProcessed" runat="server" CssClass="text" MaxLength="999999" onblur="javascript:validate();" ></asp:TextBox>
and the Javascript Code is:-
function validate() {
if (document.getElementById('<%=txtVolumeProcessed.ClientID%>').value.length > 7) {
alert("Volume Processed not exceed 999999");
document.getElementById('<%=txtVolumeProcessed.ClientID%>').select();
document.getElementById('<%=txtVolumeProcessed.ClientID%>').focus();
return false;
}
else {
return true;
}
}
If it’s an asp.net textbox, you can set the MaxLength property on it. This will accomplish what you’re looking for.