Created
August 11, 2015 15:44
-
-
Save nbpalomino/85373ced96a49a397ae4 to your computer and use it in GitHub Desktop.
Script for allow just a defined string of chars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var soloPermitir = function (a){ | |
// console.dir($(this).data('permitido')); | |
// console.dir(a.data); | |
var permitido = ($(this).data('permitido') || a.data.permitido).toString(); | |
var c=a.which, | |
d=a.keyCode, | |
e=String.fromCharCode(c).toLowerCase(), | |
f=permitido; | |
(-1!=f.indexOf(e)||9==d||37!=c&&37==d||39==d&&39!=c||8==d||46==d&&46!=c)&&161!=c||a.preventDefault(); | |
}; | |
$.fn.soloPermitir = function(b){ | |
$(this).on('keypress', {permitido: b}, soloPermitir); | |
return $(this); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment