Skip to content

Instantly share code, notes, and snippets.

@codexico
Created January 22, 2014 22:02
Show Gist options
  • Save codexico/8568280 to your computer and use it in GitHub Desktop.
Save codexico/8568280 to your computer and use it in GitHub Desktop.
char list to accept from user
function inputOnlyLetters () {
var re_letters= /^[ ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáãÃÀÁéèÈÉíìÍÌïÏóòõÕÓÒúùÚÙüÜ]+$/gi;
var re_not_letters= /[^ ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáãÃÀÁéèÈÉíìÍÌïÏóòõÕÓÒúùÚÙüÜ]/gi;
$('.not-number').on('keyup', function() {
var input = this;
// user needs some time to write chars that need two strokes, like ç => ' + c
window.setTimeout(function(){
if (!re_letters.test(input.value)) {
input.value = input.value.replace(re_not_letters, '');
}
}, 800);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment