Add number validation with javascript, for number fields

This commit is contained in:
JC 2016-11-02 11:57:07 +01:00
parent 98fe908daf
commit b03dd07d97

View file

@ -7,6 +7,10 @@ function action_type_de_champs() {
toggleErrorClass(this, validateEmail($(this).val()));
});
$("input[type='number']").on('change', function () {
toggleErrorClass(this, validateNumber($(this).val()));
});
$("input[type='phone']").on('change', function () {
val = $(this).val();
val = val.replace(/[ ]/g, '');
@ -43,6 +47,11 @@ function validateEmail(email) {
return validateInput(email, re)
}
function validateNumber(number) {
var re = /^[0-9]+$/;
return validateInput(number, re)
}
function validateInput(input, regex) {
return regex.test(input);
}