2016-06-06 16:17:19 +02:00
|
|
|
$(document).on('page:load', action_type_de_champs);
|
|
|
|
$(document).ready(action_type_de_champs);
|
|
|
|
|
|
|
|
|
|
|
|
function action_type_de_champs() {
|
|
|
|
$("input[type='email']").on('change', function () {
|
|
|
|
toggleErrorClass(this, validateEmail($(this).val()));
|
|
|
|
});
|
|
|
|
|
2016-11-02 11:57:07 +01:00
|
|
|
$("input[type='number']").on('change', function () {
|
|
|
|
toggleErrorClass(this, validateNumber($(this).val()));
|
|
|
|
});
|
|
|
|
|
2016-06-06 16:17:19 +02:00
|
|
|
$("input[type='phone']").on('change', function () {
|
|
|
|
val = $(this).val();
|
|
|
|
val = val.replace(/[ ]/g, '');
|
|
|
|
|
|
|
|
toggleErrorClass(this, validatePhone(val));
|
|
|
|
});
|
2016-06-09 12:08:18 +02:00
|
|
|
|
2016-09-22 11:31:24 +02:00
|
|
|
$("#liste_champs input").on('focus', function () {
|
|
|
|
$("#description_" + this.id).slideDown();
|
2016-06-09 14:18:28 +02:00
|
|
|
});
|
|
|
|
|
2016-09-22 11:31:24 +02:00
|
|
|
$("#liste_champs input").on('blur', function () {
|
|
|
|
$("#description_" + this.id).slideUp();
|
2016-06-09 14:18:28 +02:00
|
|
|
});
|
|
|
|
|
2016-06-09 12:08:18 +02:00
|
|
|
address_type_init();
|
2016-06-06 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleErrorClass(node, boolean) {
|
|
|
|
if (boolean)
|
|
|
|
$(node).removeClass('input-error');
|
|
|
|
else
|
|
|
|
$(node).addClass('input-error');
|
|
|
|
}
|
|
|
|
|
|
|
|
function validatePhone(phone) {
|
|
|
|
var re = /^(0|(\+[1-9]{2})|(00[1-9]{2}))[1-9][0-9]{8}$/;
|
|
|
|
return validateInput(phone, re)
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateEmail(email) {
|
|
|
|
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-11-02 11:57:07 +01:00
|
|
|
function validateNumber(number) {
|
|
|
|
var re = /^[0-9]+$/;
|
|
|
|
return validateInput(number, re)
|
|
|
|
}
|
|
|
|
|
2016-06-06 16:17:19 +02:00
|
|
|
function validateInput(input, regex) {
|
|
|
|
return regex.test(input);
|
2016-06-09 12:08:18 +02:00
|
|
|
}
|