I have problems with limitkeypress.js and IE10

In the project I'm working on, I have a text box where the user must enter his name. To avoid user input of numbers, I used the jquery.limitkeypress.js library written by Brian JΓ€ger , and everything worked fine until I checked the site in Internet Explorer 10. In IE10 you can enter all the letters you want and you cannot enter a number or strange characters the way I wanted, but when I type a space and then a letter, I see the letter is printed on the right to space, and then the space disappears, and the last moves to the left. The strange thing is that if I wait, like 30 seconds after entering a space, to print a letter, it works fine.

+4
source share
2 answers

jquery.limitkeypress.js has some problems, for example, I recommend you use a more powerful library.

http://github.com/RobinHerbots/jquery.inputmask

With this library you can use something like this:

$(".numbers").inputmask('Regex', { mask: "9", repeat: 11, placeholder: "" }); 

It works fine on ie. :)

+5
source

Sorry, I have not updated this plugin in a few years, but ...

jquery.limitkeypress now works with IE9 +, there was a problem with selecting selection.

IE11 killed support for its .selection document, but they retained document.setSelectionRange, which I used to check which browser is used ...

IE9 included document.selectionStart and document.selectionEnd, so now I check which version of IE browser is used in the browser ...

I added this to check the version of IE:

 var ie = (function(){ var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while ( div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0] ); return v > 4 ? v : undef; }()); 

So, my selection functions now look like this:

 function getSelectionStart(o) { if (ie < 9) { var r = document.selection.createRange().duplicate() r.moveEnd('character', o.value.length) if (r.text == '') return o.value.length return o.value.lastIndexOf(r.text) } else return o.selectionStart } function getSelectionEnd(o) { if (ie < 9) { var r = document.selection.createRange().duplicate() r.moveStart('character', -o.value.length) return r.text.length } else return o.selectionEnd } 
+1
source

Source: https://habr.com/ru/post/1480176/


All Articles