Skip to content

Instantly share code, notes, and snippets.

@nbpalomino
Created August 11, 2015 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbpalomino/85373ced96a49a397ae4 to your computer and use it in GitHub Desktop.
Save nbpalomino/85373ced96a49a397ae4 to your computer and use it in GitHub Desktop.
Script for allow just a defined string of chars
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