-1

I have tried approximately all the regex solution but I am still able to bypass the validation for the below email -

test_test_test@yaho..co.uk

I need to mark this email as invalid using Javascript. Please share the correct regex that I can use to mark above email as invalid.

aforankur
  • 1,291
  • 1
  • 15
  • 27

2 Answers2

0

Try this:

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 re.test(email);
}

console.log(validateEmail("test_test_test@yaho..co.uk"));
console.log(validateEmail("test_test_test@yaho.co.uk"));
Dave
  • 2,764
  • 2
  • 15
  • 27
0

You can use this one from Regex101

I think your previous regex might accidentally include \. inside character list with + quantifier, so @xx..co still can be bypass

var regex = /^[0-9a-zA-Z-_\$#]+@[0-9a-zA-Z-_\$#]+\.[a-zA-Z]{2,5}/;
console.log(regex.test('test_test_test@yaho..co.uk'));
Wenli He
  • 333
  • 3
  • 9