1

So I am trying to validate a string with contains first some text, then an email surrounded by angled brackets '<>', for example

'Test <postmaster@email.academy>'

I have been trying to solve this for quite some time, I want to know if there is a regex that will help me to validate that the email is always surrounded by angled brackets

var data = {
    from: 'Test <postmaster@email.com>',
};

var dataValidation = function (data){
    var fromEmailAddress = data.from.split(' '); //['Test','<postmaster@email.com>']
    /////code below doesn't work as I have angled brackets around the email
    var validEmail = /^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+.)+([A-Za-z0-9]{2,4}|museum)$/;
    if(validEmail.test(fromEmailAddress[1])){
        console.log(fromEmailAddress[1])
    }

};
Rajat Garg
  • 552
  • 2
  • 11
  • 23
Adam
  • 2,291
  • 3
  • 14
  • 21

0 Answers0