For some reason my form is letting blank email addresses slip by. It will validate them if they're input incorrectly, but does nothing if the string is <2 characters.
I have 1% idea what I'm doing with JS..please help me gently. =)
....there is more to this code, but nothing pertaining the problem ( I don't think!)Code:function test(src) { var emailReg = "^[\\w-_'\.]*[\\w-_'\.]\@[\\]\.+[\\w-_]+[\\w]$"; var regex = new RegExp(emailReg); return regex.test(src); } function validate() { var i=0; var errcolour='#CC3300'; var msg='The following fields did not pass validation:\n\n'; if(document.guestbook.EMAIL.value.length >1) { emailValid = test(document.guestbook.EMAIL.value); if(emailValid == false) { ++i; msg += "Your E-mail address is not valid.\n"; document.guestbook.EMAIL.style.background=errcolour; document.guestbook.EMAIL.style.color='#FFFFFF'; }else{ document.guestbook.EMAIL.style.background='#FFFFFF'; document.guestbook.EMAIL.style.color=''; } } if(document.guestbook.EMAIL.value.length <2) { ++i; msg += 'You must supply a valid email address\n'; document.guestbook.EMAIL.style.background=errcolour; document.guestbook.EMAIL.style.color='#FFFFFF'; }else{ document.guestbook.EMAIL.style.background='#FFFFFF'; document.guestbook.EMAIL.style.color=''; }
Thanks!




Bookmarks