2017-03-30 17:00:35 +02:00
|
|
|
$(document).on('turbolinks:load', action_type_de_champs);
|
2016-06-06 16:17:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
function action_type_de_champs() {
|
2017-04-04 16:15:33 +02:00
|
|
|
$("input[type='email']").on('change', function () {
|
|
|
|
toggleErrorClass(this, validateEmail($(this).val()));
|
|
|
|
});
|
2016-06-06 16:17:19 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
$("input[type='number']").on('change', function () {
|
|
|
|
toggleErrorClass(this, validateNumber($(this).val()));
|
|
|
|
});
|
2016-11-02 11:57:07 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
$("input[type='phone']").on('change', function () {
|
|
|
|
val = $(this).val();
|
|
|
|
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-09 12:08:18 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
address_type_init();
|
2016-06-06 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleErrorClass(node, boolean) {
|
2017-04-04 16:15:33 +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}$/;
|
|
|
|
return validateInput(phone, re)
|
2016-06-06 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateEmail(email) {
|
2017-04-04 16:15:33 +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]+$/;
|
|
|
|
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
|
|
|
}
|