Created
August 20, 2012 17:54
-
-
Save zodman/3406151 to your computer and use it in GitHub Desktop.
Validando caracteres extraños en un input
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
(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