468,301 Members | 1,396 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

javascript mozill problem

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
3 1534
acoder
16,027 Expert Mod 8TB
How are you calling text()?
Jun 18 '07 #2
sattu
11
How are you calling text()?
i am calling text() on textbox onkeypress event like
onKeyPress="return text(event)"
Jun 21 '07 #3
acoder
16,027 Expert Mod 8TB
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.

Similar topics

13 posts views Thread by Kai Grossjohann | last post: by
6 posts views Thread by Andy Fish | last post: by
136 posts views Thread by Matt Kruse | last post: by
7 posts views Thread by parghi | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.