Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The validation for input type number(n>=0) by JavaScript
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