By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

text box validation

P: 10
I am doing text box validation in form.

I did the following validations.

1)Special characters like $,#,etc should not be allowed to enter by user.
2)Only alphanumerical characters should be allowed to enter in text box.
3)The maximum length is 10. After that the user should not be allowed to enter any character.

I am facing the following problem.

pbm:
I entered the characters upto maximum length, then i want to change the value. I pressed SHIFT + HOME key. All the values in text box are selected. Then i enter a new character to replace the old string. But the string could not be deleted when new character key is pressed.


Please give solution for this. Otherwise please give the perfect validation sample coding.

Please help me. Advance thanks.
Sep 4 '06 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
[HTML]<script type="text/javascript">
function alphaNumOnly(e) {
keycode = e.keyCode || e.which;
keychar = String.fromCharCode(keycode);
keycheck = /\d|[a-z]/i
return keycheck.test(keychar);
}
</script>

<form>
<input type="text" onkeypress="return alphaNumOnly(event)" maxlength="10">
</form>[/HTML]
May 6 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.