Skip to content

Instantly share code, notes, and snippets.

@k0ta0uchi
Created March 8, 2018 09:46
Show Gist options
  • Save k0ta0uchi/9a3ad2173245f6917a9e08c4772e6a9e to your computer and use it in GitHub Desktop.
Save k0ta0uchi/9a3ad2173245f6917a9e08c4772e6a9e to your computer and use it in GitHub Desktop.
simple validator
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