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

javascript mozill problem

P: 11
hello friends

i am doing validation on textbox through javascript
i have written a function on KeyPress Event of textbox
to enter text only means (a-z,A-Z)
it is working fine in IE but in mozilla the backspace and delete keys are not working
if i enter text in textbox then press backspace then it doesnt work
please tell me soln

function text(event)
{

var keycode;
if (window.event)
keycode = window.event.keyCode;
else
keycode = event.which;
if(keycode>=65 && keycode<=90 && || keycode>=97 && keycode<=122)
return true;

else
return false;

}
Jun 18 '07 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
How are you calling text()?
Jun 18 '07 #2

P: 11
How are you calling text()?
i am calling text() on textbox onkeypress event like
onKeyPress="return text(event)"
Jun 21 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Backspace's unicode is 8 and delete's is 46. You need to check for those and allow them.

You can also make your code shorter and easier on the check for alphabetic characters by using regular expressions:
Expand|Select|Wrap|Line Numbers
  1. alphacheck = /[a-zA-Z]/
  2. return !alphacheck.test(keycode)
though you would add in checks for backspace and delete too.
Jun 21 '07 #4

Post your reply

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