Jquery check if input .val() contains certain characters
<p>I need to check if an input field on my page contains characters.</p>

<p>This is for very basic email address validation so I only want to check if the text is not empty, and contains <code>@</code> and <code>.</code> characters.</p>

<p>I've been trying this way:</p>

<pre><code>if (($("." + parentname.attr("class") + " #email").val().contains("@")) &amp;&amp; ($("." + parentname.attr("class") + " #email").val().contains(".")))
{
    email = 1;
}
</code></pre>

<p>Assuming a value of <code>me@this.com</code>, this code will throw the following error:</p>

<blockquote>
  <p>Object me@this.com has no method 'contains'</p>
</blockquote>

<p>So I did some research and found that .contains is for DOM objects, not strings with a suggestion to try this:</p>

<pre><code>if (($("." + parentname.attr("class") + " #email").val().IndexOf("@") != -1) &amp;&amp; ($("." + parentname.attr("class") + " #email").val().IndexOf(".") != -1))
{
    email = 1;
}
</code></pre>

<p>Which results in a similar error:</p>

<blockquote>
  <p>Object me@this.com has no method 'IndexOf'</p>
</blockquote>

<p>I'm basically out of ideas here especially considering that the following code works as I want it to in another site I've made:</p>

<pre><code>if ($("#contact-email").val().contains("yahoo.com")) {
    $(".errmsg").text("Domain yahoo.com has been banned due to excessive spam, please use another domain.");
}
</code></pre>

<p>Can anyone suggest any other things I could try or, better yet, how to do this properly?</p>
