How to check if event target value contains substring in Javascript

Viewed 30

I want to check if the value of an input field is a valid email address by checking if the e.target.value contains "@"

// HTML

<input type="text" id="signUpMail" class="form__input" autofocus placeholder="E-Mail">

// JS

if(e.target.id === 'signUpMail' && e.target.value.length > 0 && e.target.value.indexOf('@') === -1){do something};

Unfortunately e.target.value.indexOf('@') === -1 does not seem to work. Are the any other possibilities to check if the e.target.value contains the @ character?

Thanks!

0 Answers
Related