Add number validation with javascript, for number fields
This commit is contained in:
parent
98fe908daf
commit
b03dd07d97
1 changed files with 10 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue