0

How can I amend this to check that x also contains @? I've tried using includes() but that does not work.

I realise this is probably simple but I just can't seem to get it

EDIT

using either includes() or indexof() results in this error:

"'); debugger" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.

 var x = document.getElementById('emailEntry').value;

    var doesContain = x.includes('@');

    if (x == null || x == "" || !doesContain) {
        document.getElementById('message').style.display = "block";
        document.getElementById('message').innerHTML = "Email must not be blank";
    }
8
  • Can you post the code with includes? If the input is a string then it should definitely work with includes() Commented Sep 5, 2019 at 14:06
  • Should work like if( ... || x.includes("@")) { ... } Commented Sep 5, 2019 at 14:07
  • @AjayGupta includes() is for arrays, they want indexOf() instead Commented Sep 5, 2019 at 14:08
  • Split the string and find that character in array. Commented Sep 5, 2019 at 14:11
  • I doubt that includes() only works for arrays. Check this out developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Sep 5, 2019 at 14:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.