首页 > 解决方案 > 如何检查电子邮件格式是否有效?并且两个密码匹配?反应原生

问题描述

我在 React Native 中做了一个简单的注册表单。我想检查电子邮件格式是否有效,我希望用户重新输入密码并检查两个密码是否相互匹配。我是新手,所以请让我知道如何将您的代码与我的代码结合起来。

    export class Register extends Component {
     constructor(props) {
         super(props);
         this.state = { 
             email: '',
             password: '',
             name: '',
             lastname: ''
         }
this.onSignUp = this.onSignUp.bind(this)

     }
onSignUp(){
    if(
        this.state.email != '' &&
        this.state.password != '' &&
        this.state.name != '' 
      ){
    const { email, password, name } = this.state;
    firebase.auth().createUserWithEmailAndPassword(email, password)
    .then((result) => {
        firebase.firestore().collection("Users")
            .doc(firebase.auth().currentUser.uid)
            .set({
                name,
                email
            })
        console.log(result)
    })
    .catch((error) => {
        console.log(error)
    })
}
else{
    alert("Please fill the empty spaces!");
}

}

    render() { form body } 

标签: react-native

解决方案


这可能会有所帮助:https://stackoverflow.com/questions/61933102/sending-verification-email-with-firebase-and-react-native\ 我认为除了解析之外没有办法检查某些内容是否有效字符串 a 检查它是否在正确的位置包含 @ 和 .com/org/etc..,除了发送和电子邮件并等待无响应。


推荐阅读