Skip to content

Instantly share code, notes, and snippets.

@nian88
Created July 12, 2022 02:20
Show Gist options
  • Save nian88/371f4bfd62e5520df1fcb7748987b93e to your computer and use it in GitHub Desktop.
Save nian88/371f4bfd62e5520df1fcb7748987b93e to your computer and use it in GitHub Desktop.
memfilter inputan pada text html
$( document ).ready(function() {
$('.noSymbol').keypress(function (e) {
var txt = String.fromCharCode(e.which);
if (!txt.match(/[A-Za-z0-9&.]/)) {
return false;
}
});
$('.numberOnly').keypress(function (e) {
var txt = String.fromCharCode(e.which);
if (!txt.match(/[0-9.]/)) {
return false;
}
});
$('.numberOnly').focusout(function (e) {
var el = this;
if (!el.value >0) {
el.value ='';
}
});
$('.numberOnly').focusin(function (e) {
var el = this;
if (el.value ==0) {
el.value ='';
}
});
$('.numberOnly').bind('paste', function() {
var el = this;
setTimeout(function() {
el.value = el.value.replace(/\D/g, '');
}, 0);
});
$('.aphaOnly').keypress(function (e) {
var txt = String.fromCharCode(e.which);
if (!txt.match(/[A-Za-z. ]/)) {
return false;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment