PDA

View Full Version : Help with a this e-mail validation function



binici
05-25-2006, 05:59 PM
It works when I don't input a correct e-mail format, but when I do, it won't let me go to the next field, it focuses on that field and selects it. What am i missing?

Thanks!

function checkEmail(field, fieldname){
var x = field.value;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(field.value.length > 0 ) {
if (filter.test(x));
else alert('Oops! This doesn\'t appear to be a valid e-mail address.');
field.focus();
field.select();
}
}

Twey
05-25-2006, 06:21 PM
Why wouldn't it?
You've told it to.

I think you mean to say:
function checkEmail(field, fieldname) {
var x = field.value,
filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(field.value.length > 0 && !filter.test(x)) {
alert('Oops! This doesn\'t appear to be a valid e-mail address.');
field.focus();
field.select();
}
}