JavaScript - How to enable arrow key in Firefox browser while validating input fields against special characters -


i'm validating input field using key code enter (a-z, a-z, _). javascript code looks this:

function checkforspecialcharacters(event) { var keycode;  keycode = event.keycode ? event.keycode : event.which;  if ((keycode >= 48 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode == 9)         || (keycode == 95)||(keycode == 8) || (keycode >= 97 && keycode <= 122)) {      return true;  }  else {      return false;  } return true; 

}

this works pretty fine in chrome, ies, in firefox prevents arrow key also.

i've gone through what ascii values of down left right?. in case need prevent enter special characters in input field.
give solution in above link not fulfill requirement.

kindly reply positive response.

thanks.

got solution of problem. use event.which. here which property of event object. contains key code of key pressed trigger event (eg: keydown, keyup etc.).

so value fo key pressed using event.which , check in if condition.

in case in firefox browser getting 0 arrow keys. added on more or condition like:

if ((keycode >= 48 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode == 9)  || (event.which == 0)  || (keycode == 95)||(keycode == 8) || (keycode >= 97 && keycode <= 122)) {  return true;} 

hope other pal.

thanks


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -