From 858df4457c7f6197e8072a1490a799f5ceafc8a0 Mon Sep 17 00:00:00 2001 From: Mark Gavillet Date: Thu, 7 Apr 2011 16:19:05 +0100 Subject: [PATCH] Bug: 5685 - Email address format validation for patron records --- koha-tmpl/intranet-tmpl/prog/en/js/members.js | 30 ++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/members.js b/koha-tmpl/intranet-tmpl/prog/en/js/members.js index 796db0a..ef15c3f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/members.js @@ -84,6 +84,8 @@ var myDate2=document.form.dateexpiry.value.split ('/'); // function to test all fields in forms and nav in different forms(1 ,2 or 3) function check_form_borrowers(nav){ + //alert('email'+document.form.email.value+'\nemailpro:'+document.form.emailpro.value+'\nB_email:'+document.form.B_email.value); + var statut=0; if (document.form.check_member.value == 1 ) { @@ -139,7 +141,33 @@ function check_form_borrowers(nav){ document.form.nodouble.value=1; } } - + + //validate email addresses + function isValidEmailAddress(emailAddress) { + var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); + return pattern.test(emailAddress); + } + if (statut!=1) { + if (document.form.email.value != 0 && (!isValidEmailAddress(document.form.email.value))) + { + message=''; + statut=1; + message_champ+=document.form.email.value+' is not a valid email address\n'; + } + if (document.form.emailpro.value != 0 && (!isValidEmailAddress(document.form.emailpro.value))) + { + message=''; + statut=1; + message_champ+=document.form.emailpro.value+' is not a valid email address\n'; + } + if (document.form.B_email.value != 0 && (!isValidEmailAddress(document.form.B_email.value))) + { + message=''; + statut=1; + message_champ+=document.form.B_email.value+' is not a valid email address\n'; + } + } + if (statut==1){ //alert if at least 1 error alert(message+"\n"+message_champ); -- 1.5.6.5