Regex in React email validation : <p>I'm trying to set an error for when the email isn't correct. When I'm checking if the string is empty the form alerts with the proper message. But when I'm checking if the email matches the regular expression it doesn't work. Any ideas?</p>

<pre><code>import React, { Component } from 'react';
import { Link } from 'react-router';
// Our custom input component, which uses label, id and tabIndex properties
var MyInput = React.createClass({
  render: function() {

    // Get the error message by calling a function, passed to this
    // component through getError property
    var errorMessage = this.props.getError(this.props.id);

    return (
        &lt;fieldset className={"form-fieldset ui-input first " + (errorMessage ?    "erroneous" : "")}&gt;
            &lt;input type="text" name={this.props.id} id={this.props.id} tabIndex={this.props.tabIndex} /&gt;
            &lt;label htmlFor={this.props.id}&gt;
              &lt;span data-text={this.props.label}&gt;{this.props.label}&lt;/span&gt;
            &lt;/label&gt;
            &lt;span className="error"&gt;{errorMessage ? errorMessage : null}&lt;/span&gt;
          &lt;/fieldset&gt;
    )
  }
});

// Form
var SendForm = React.createClass ({
  getError: function (fieldName) {
    return this.state[fieldName+"Error"];
  },
  setError: function (fieldName, error) {
    var update = {};
    update[fieldName+"Error"] = error;
    this.setState(update);
  },
  getInitialState: function() {
    return {
      isMailSent: false,
      errorMessage: null,
    };
  },
  componentDidMount: function () {
    // This will be called right when the form element is displayed
    $('form').parsley()
  },
  validateForm: function(){
    var hasErrors = false;

    if ($('#company').val().length &lt; 1){
      this.setError("company", "Please enter your company name");
      hasErrors = true;
    } else this.setError("company", null)

    if ($('#industry').val().length &lt; 1){
      this.setError("industry", "Please enter the industry");
      hasErrors = true;
    } else this.setError("industry", null)

    if ($('#firstName').val().length &lt; 1){
      this.setError("firstName", "Please enter your first name");
      hasErrors = true;
    } else this.setError("firstName", null)

    if ($('#lastName').val().length &lt; 1) {
      this.setError("lastName", "Please enter your last name");
      hasErrors = true;
    } else this.setError("lastName", null)

    if ($('#email').val() == '') {
      this.setError("email", "Please enter your email address");
      hasErrors = true;
    } else this.setError("email", null)

    if ($('#email').val() !== /^[a-zA-Z0-9]+@+[a-zA-Z0-9]+.+[A-z]/) {
      this.setError("email", "Please enter a valid email address");
      hasErrors = true;
    } else this.setError("email", null)


    if ($('#phone').val().length &lt; 1) {
      this.setError("phone", "Please enter your phone number");
      hasErrors = true;
    } else this.setError("phone", null)

    return !hasErrors;
  },
  handleSubmit: function (e) {
    e.preventDefault();

    // Check if data is valid
    if (!this.validateForm()) {
      //return if not valid
      return;
    }

    // Get the form.
    var form = $('form');

    // Serialize the form data.
    var formData = $(form).serialize();

    var self = this;
    console.log(formData)
    // Submit the form using AJAX.
    $.ajax({
      type: 'POST',
      url: 'email-handler.php',
      data: formData
    }).done(function(response) {

      // Update the state, notifying that mail was sent
      // This value will be used in the form when rendering
      self.setState({isMailSent: true})

      // Hide the form
      $('.formCont').hide();
    }).fail(function(data) {
      // Make sure that the formMessages div has the 'error' class.
      self.setState({errorMessage : "Something went wrong. Please try again."});
    });
  },
 render: function(){
   return (
     &lt;div className="companyForm"&gt;

       &lt;h2 className="header compFormHead"&gt;Form&lt;/h2&gt;

       { this.state.isMailSent ?
           &lt;div className="success"&gt;Thank you for submission. Someone will be in contact with you shortly.&lt;/div&gt;
           : null }

       &lt;div className="container formCont"&gt;
         &lt;form method="post" acceptCharset="utf-8" autoComplete="off" onSubmit={this.handleSubmit}&gt;

         &lt;MyInput id="company" label="Company" tabIndex="1" getError={this.getError}/&gt;
         &lt;MyInput id="industry" label="Industry" tabIndex="2" getError={this.getError}/&gt;

         &lt;div className="two-column"&gt;
           &lt;MyInput id="firstName" label="First Name" tabIndex="3" getError={this.getError}/&gt;
           &lt;MyInput id="lastName" label="Last Name" tabIndex="4" getError={this.getError}/&gt;
         &lt;/div&gt;
         &lt;div className="two-column"&gt;
           &lt;MyInput id="email" type="email" label="Email" tabIndex="5" getError={this.getError}/&gt;
           &lt;MyInput id="phone" label="Phone" tabIndex="6" getError={this.getError}/&gt;
         &lt;/div&gt;

         {this.state.errorMessage ? &lt;div className="fail"&gt;{this.state.errorMessage}&lt;/div&gt; : null}

         &lt;div className="form"&gt;
           &lt;input type="submit" name="submit" className="btn btn-primary" value="APPLY" tabIndex="7" /&gt;
         &lt;/div&gt;

         &lt;/form&gt;
       &lt;/div&gt;

     &lt;/div&gt;
   );
 }
});

export default SendForm;
</code></pre>
