This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Backspace, Del, Arrow keys, Tab not working in Firefox when applying validation

  • 2 replies
  • 20 have this problem
  • 1 view
  • Last reply by shitiz13

more options

Hi,

I am developing a webpage with some textboxes requiring only alphabets or alphanumeric text to be accepted. I am using DevExpress controls and following is the javascript code that executes on keypress

function fn_allowAlphabetspace(s, e) {

           var theEvent = e.htmlEvent || window.event;
           var key = theEvent.keyCode || theEvent.which;
           debugger;
           key = String.fromCharCode(key);
           var regex = /[a-zA-Z ]/;
           if (!regex.test(key)) {
               theEvent.returnValue = false;
               if (theEvent.preventDefault)
                   theEvent.preventDefault();
           }
       }

All the browsers except firefox allow Backspace, Del, Tab, Arrow keys, Home, End key to work perfectly. Firefox does not allow any of these to work on the textboxes.

Thanks Shitiz

Hi, I am developing a webpage with some textboxes requiring only alphabets or alphanumeric text to be accepted. I am using DevExpress controls and following is the javascript code that executes on keypress function fn_allowAlphabetspace(s, e) { var theEvent = e.htmlEvent || window.event; var key = theEvent.keyCode || theEvent.which; debugger; key = String.fromCharCode(key); var regex = /[a-zA-Z ]/; if (!regex.test(key)) { theEvent.returnValue = false; if (theEvent.preventDefault) theEvent.preventDefault(); } } All the browsers except firefox allow Backspace, Del, Tab, Arrow keys, Home, End key to work perfectly. Firefox does not allow any of these to work on the textboxes. Thanks Shitiz

Chosen solution

Hi,

I tried to solve it by debugging the javascript and found the below code to be working for firefox as well as on other browsers IE10, Chrome and Safari without any issues

//validation function to allow only alphabets and space

       function fn_allowAlphabetspace(s, e) {
           var searchSpecial = '$Backspace$Del$Home$Tab$Left$Right$Up$Down$End$';
           if (searchSpecial.indexOf('$' + e.htmlEvent.key + '$') < 0) {
               var theEvent = e.htmlEvent || window.event;
               var key = theEvent.keyCode || theEvent.which;
               key = String.fromCharCode(key);
               var regex = /[a-zA-Z ]/;
               if (!regex.test(key)) {
                   theEvent.returnValue = false;
                   if (theEvent.preventDefault)
                       theEvent.preventDefault();
               }
           }
       }

Please not that parameter e passed in the function provide the details of the keypress function. I am using DevExpress ASPxTextBoxes. Anybody who wants to use this function need to make changes in the above code as per the control used

Thanks Shitiz

Read this answer in context 👍 0

All Replies (2)

more options

Forgot to mention, DevExpress is a third party tool that I am using.

Modified by shitiz13

more options

Chosen Solution

Hi,

I tried to solve it by debugging the javascript and found the below code to be working for firefox as well as on other browsers IE10, Chrome and Safari without any issues

//validation function to allow only alphabets and space

       function fn_allowAlphabetspace(s, e) {
           var searchSpecial = '$Backspace$Del$Home$Tab$Left$Right$Up$Down$End$';
           if (searchSpecial.indexOf('$' + e.htmlEvent.key + '$') < 0) {
               var theEvent = e.htmlEvent || window.event;
               var key = theEvent.keyCode || theEvent.which;
               key = String.fromCharCode(key);
               var regex = /[a-zA-Z ]/;
               if (!regex.test(key)) {
                   theEvent.returnValue = false;
                   if (theEvent.preventDefault)
                       theEvent.preventDefault();
               }
           }
       }

Please not that parameter e passed in the function provide the details of the keypress function. I am using DevExpress ASPxTextBoxes. Anybody who wants to use this function need to make changes in the above code as per the control used

Thanks Shitiz