Created
March 8, 2018 09:46
-
-
Save k0ta0uchi/9a3ad2173245f6917a9e08c4772e6a9e to your computer and use it in GitHub Desktop.
simple validator
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
var check = (target) => { | |
var regex = new RegExp('^(\\+|\\-)?(0[1-9]{0,2}|\\d{0,3})(,\\d{3})*(\\.[0-9]+)?$', 'g'); | |
return target.search( regex ) ? true : false; | |
} | |
var isValid = true; | |
var inputs = window.document.querySelectorAll('input[type=text].reqular-text'); | |
inputs.forEach((val) => { | |
val.addEventListener('input', (e) => { | |
const tooltip = new Tooltip(this, { | |
title: "数値が正しくありません。", | |
placement: "bottom" | |
}); | |
if (!check(this.value)) { | |
tooltip.show(); | |
isValid = false; | |
} else { | |
tooltip.hide(); | |
isValid = true; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment