Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE not work #3

Open
michalwroblewski opened this issue Mar 16, 2011 · 2 comments
Open

IE not work #3

michalwroblewski opened this issue Mar 16, 2011 · 2 comments

Comments

@michalwroblewski
Copy link

It is the resolution of problem

$(this).keypress(function (e) {
var k = e.charCode || e.keyCode || e.which;
var pos = $(this).caret();
if (!k){
return true;
}
var part1 = this.value.substring(0, pos.begin);
var part2 = this.value.substring(pos.end, this.value.length);
if (!mask.test(part1 + String.fromCharCode(k) + part2)){
return false;
}else{
return true;
}
});

@michalwroblewski
Copy link
Author

function checkKey(e){
var k = e.charCode || e.keyCode || e.which;
if (!(e.ctrlKey || e.altKey || e.metaKey) && ((k >= 32 && k <= 125) || k > 186)){
return k;
}
return null;
}

    $(this).keypress(function (e) {
        var k = checkKey(e);
        if (!k) {
            return true;
        }

        var pos = $(this).caret();
        var part1 = this.value.substring(0, pos.begin);
        var part2 = this.value.substring(pos.end, this.value.length);
        if (!mask.test(part1 + String.fromCharCode(k) + part2)){
            return false;
        }else{
            return true;
        }
    });

@amid2887
Copy link

amid2887 commented Jul 3, 2012

I'm also see problems in IE...
Solve it by that way:

  if (!event.which) return true;

  var begin, end;

  if (this.setSelectionRange) {
    begin = this.selectionStart;
    end = this.selectionEnd;
  } else if (document.selection && document.selection.createRange) {
    var range = document.selection.createRange();
    begin = 0 - range.duplicate().moveStart('character', -100000);
    end = begin + range.text.length;
  }

  var part1 = this.value.substring(0,begin);
  var part2 = this.value.substring(end,this.value.length);

  if (!mask.test(part1 + String.fromCharCode(event.which) + part2)){
    return false;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants