2013-06-20 15:15:39 +00:00

56 lines
1.6 KiB
JavaScript

function validate() {
var allvals = true;
$("[required]").each(function() {
if(!$(this).val()) {
allvals = false;
$(this).addClass('brsr');
}
else { $(this).removeClass('brsr'); }
});
return allvals;
}
function isEmail(email) {
var emailval = true;
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!regex.test(email.val())) {
emailval = false;
$(email).addClass('brsr');
}
else {
$(email).removeClass('brsr');
}
return emailval;
}
$(document).ready(function(){
validate();
isEmail($('[name=email]'));
});
$('[required]').blur(function(){
validate();
isEmail($('[name=email]'));
});
$('#dlg').dialog({ buttons: [
{ text: "Valider", click: function() {
var values = $(this).find('form').serialize();
if (validate() && isEmail($('[name=email]'))) {
if ($('.loading').css('display')=='none') {
$('.loading').css('display', 'block');
$('.ui-dialog-content').css('overflow','hidden');
$(".ui-dialog-buttonpane button:contains('Valider')").button("disable");
}
else { $('.loading').css('display', 'none');}
$.post('/user/motpasse', values, function(data) {
$('#dlg').html(data);
$('pre').hide();
$('#htxt').height(50);
$('input#frm').attr("disabled", "disabled");
$(".ui-dialog-buttonpane button:contains('Valider')").hide();
});
}
}},
{ text: "Annuler", click: function() { $(this).dialog('close'); }}
] });