2018-10-02 16:59:30 +02:00
|
|
|
/* globals $ */
|
2016-06-06 16:17:19 +02:00
|
|
|
|
2020-05-07 16:31:36 +02:00
|
|
|
$(document).on('DOMContentLoaded', action_type_de_champs);
|
2016-06-06 16:17:19 +02:00
|
|
|
|
|
|
|
function action_type_de_champs() {
|
2020-04-30 15:42:29 +02:00
|
|
|
$("input[type='email']").on('change', function () {
|
2017-04-04 16:15:33 +02:00
|
|
|
toggleErrorClass(this, validateEmail($(this).val()));
|
|
|
|
});
|
2016-06-06 16:17:19 +02:00
|
|
|
|
2020-04-30 15:42:29 +02:00
|
|
|
$("input[type='number']").on('change', function () {
|
2017-04-04 16:15:33 +02:00
|
|
|
toggleErrorClass(this, validateNumber($(this).val()));
|
|
|
|
});
|
2016-11-02 11:57:07 +01:00
|
|
|
|
2020-04-30 15:42:29 +02:00
|
|
|
$("input[type='phone']").on('change', function () {
|
2018-10-02 16:59:30 +02:00
|
|
|
var val = $(this).val();
|
2017-04-04 16:15:33 +02:00
|
|
|
val = val.replace(/[ ]/g, '');
|
2016-06-06 16:17:19 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
toggleErrorClass(this, validatePhone(val));
|
|
|
|
});
|
2016-06-06 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleErrorClass(node, boolean) {
|
2018-10-02 16:59:30 +02:00
|
|
|
if (boolean) $(node).removeClass('input-error');
|
|
|
|
else $(node).addClass('input-error');
|
2016-06-06 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function validatePhone(phone) {
|
2017-04-04 16:15:33 +02:00
|
|
|
var re = /^(0|(\+[1-9]{2})|(00[1-9]{2}))[1-9][0-9]{8}$/;
|
2018-10-02 16:59:30 +02:00
|
|
|
return validateInput(phone, re);
|
2016-06-06 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateEmail(email) {
|
2018-10-02 16:59:30 +02:00
|
|
|
var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
|
|
return validateInput(email, re);
|
2016-06-06 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 11:57:07 +01:00
|
|
|
function validateNumber(number) {
|
2017-04-04 16:15:33 +02:00
|
|
|
var re = /^[0-9]+$/;
|
2018-10-02 16:59:30 +02:00
|
|
|
return validateInput(number, re);
|
2016-11-02 11:57:07 +01:00
|
|
|
}
|
|
|
|
|
2016-06-06 16:17:19 +02:00
|
|
|
function validateInput(input, regex) {
|
2017-04-04 16:15:33 +02:00
|
|
|
return regex.test(input);
|
2016-06-09 12:08:18 +02:00
|
|
|
}
|