Email Validation (React Native). Returning the result as 'invalid' for all the entries

后端 未结 6 706
故里飘歌
故里飘歌 2020-12-30 21:34

I am trying to validate a users email, by checking it against an expression. But the result i am getting is invalid for all the entries.

UPDATED CODE

6条回答
  •  甜味超标
    2020-12-30 22:12

    Ok I got the code working, below you can take the look for validating the email on each user input :

    1. Your function part:
    validate = (text) => {
      console.log(text);
      let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
      if (reg.test(text) === false) {
        console.log("Email is Not Correct");
        this.setState({ email: text })
        return false;
      }
      else {
        this.setState({ email: text })
        console.log("Email is Correct");
      }
    }
    
    1. You TextInput Component:
     this.validate(text)}
      value={this.state.email}
    />
    

提交回复
热议问题