Skip to content

Instantly share code, notes, and snippets.

@maecha
Last active August 22, 2018 04:14
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 maecha/f5210af8520ccc0d8818752e6304001b to your computer and use it in GitHub Desktop.
Save maecha/f5210af8520ccc0d8818752e6304001b to your computer and use it in GitHub Desktop.
The validation for input type number(n>=0) by JavaScript
// KUSO-CODE
export class HogeCustomValidatior {
positiveIntegerValidatator() {
let elm1 = document.getElementById('number_hoge1');
let elm2 = document.getElementById('number_hoge2');
let elms = [elm1, elm2];
elms.forEach(function (elm) {
elm.addEventListener('change', function(event){
if (event.target.value.match(/\D/)) {
event.target.value = null;
}
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment