-1

This shows a warning of Unnecessary escape character. how do I resolve this.

    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(String(email).toLowerCase());
    };
chintuyadavsara
  • 1,509
  • 1
  • 12
  • 23
Syed Ahmed
  • 112
  • 1
  • 7

1 Answers1

0

There is one unnecessary escape, and that's \[ within the character class:

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,}))$/;

You do need to escape the ] because it would otherwise end the character class, but an opening bracket is only a metacharacter when it's not inside a character class.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561