Skip to content

Instantly share code, notes, and snippets.

@zodman
Created August 20, 2012 17:54
Show Gist options
  • Save zodman/3406151 to your computer and use it in GitHub Desktop.
Save zodman/3406151 to your computer and use it in GitHub Desktop.
Validando caracteres extraños en un input
(function($){
$.fn.invalid_chars = function(){
return this.each(function(){
var obj = $(this);
obj.unbind("keyup");
obj.bind("keyup",function (e){
var val = $(this).val();
var regex = /[\%\(\)\:\%\<\>\$\&\=\?\¿\"\#\·\ç\}\{\`\^]+/;
var is_valid = !regex.test(val);
console.log(is_valid, val, $(this));
if(!is_valid){
val = val.replace(regex, "");
}
$(this).val(val);
});
});
}
$(document).ready(function(){
$("input:text").invalid_chars();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment