title: Validate e-mail address when pressing a button
body: <p>I'm trying to make a basic login screen. However, I'm struggling with the e-mail validation.</p>
  
  <p>Every time I press a button, I want to make sure that the user inputs the correct e-mail format, or give them a small alert under the e-mail TextInput if they write something other than a valid e-mail (this alert will be hidden by default.). However, when I try, it always gives me this error (regardless of the user input):</p>
  
  <pre><code>undefined is not an object (evaluating 'this.state.username')
  </code></pre>
  
  <p>This is my code so far</p>
  
  <pre><code>class HomeScreen extends Component {
   state = { username: null, password: null }
   show = false;
  
   _validar = (text) =&gt; {
    let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ;
  
    if(reg.test(text) === false) {
      return false;
    } else {
      return true;
    }
   }
  
   _onSubmit() {
    if(this._validar(this.state.username) == true) {
      const { username, password } = this.state;
    } else {
      this.show = true;
    }
   }
  
   render() {
    return (
     &lt;KeyboardAwareScrollView contentContainerStyle={styles.container} scrollEnabled 
     enableOnAndroid={true} resetScrollToCoords={{x:0, y:0}}&gt; 
      &lt;View style={styles.logo}&gt;
       &lt;Image source = {logo} style={styles.img}/&gt;
       &lt;Text style={styles.textLogoPrimary}&gt;Neuron App&lt;/Text&gt;
       &lt;Text style={styles.textLogoSecondary}&gt;Test&lt;/Text&gt;
      &lt;/View&gt;
  
      &lt;View style={styles.formElement}&gt;
       &lt;Text style={styles.formText}&gt;Correo Electrónico&lt;/Text&gt;
       &lt;TextInput keyboardType='email-address' placeholder='Email' onChangeText={value =&gt; this.setState({ username: value })} 
       style={styles.formInput} /&gt;
       {this.state.show ? (
         &lt;Text style={styles.textAlert}&gt;Correo Electrónico no valido.&lt;/Text&gt; 
       ) : null}       
      &lt;/View&gt;
  
      &lt;View style={styles.formElement}&gt;
       &lt;Text style={styles.formText}&gt;Contraseña&lt;/Text&gt;
       &lt;TextInput style={styles.formInput} onChangeText={value =&gt; this.setState({ password: value })} secureTextEntry={true}/&gt;
      &lt;/View&gt;
  
      &lt;View style={styles.buttonView}&gt;
       &lt;TouchableOpacity style={styles.button} onPress={this._onSubmit}&gt;
        &lt;Text style={styles.buttonText}&gt;Iniciar&lt;/Text&gt;
       &lt;/TouchableOpacity&gt;
      &lt;/View&gt;     
    &lt;/KeyboardAwareScrollView&gt;
   );
  }}
  </code></pre>