Last active
August 22, 2018 04:14
-
-
Save maecha/f5210af8520ccc0d8818752e6304001b to your computer and use it in GitHub Desktop.
The validation for input type number(n>=0) by JavaScript
This file contains 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
// 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