We're calling on all EU-based Mozillians with iOS or iPadOS devices to help us monitor Apple’s new browser choice screens. Join the effort to hold Big Tech to account!

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

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

  • 2 回覆
  • 20 有這個問題
  • 1 次檢視
  • 最近回覆由 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

被選擇的解決方法

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

從原來的回覆中察看解決方案 👍 0

所有回覆 (2)

more options

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

由 shitiz13 於 修改

more options

選擇的解決方法

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