how to validate email before enter to the home page flutter

北慕城南 提交于 2021-02-11 14:13:46

问题


i'm trying to validate my email before the user can enter to the home page. the problem is when i fill the email and password user with aaany thing it give the access without any check. here is my code for sign in page

and this is the code of sign up screen


回答1:


If it is all about validating the email for formatting, then what you can do is shown below. Put it in your email address validator you are submitting the data for Login/Register

validator: (value){
    Pattern pattern = r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
    RegExp regex = new RegExp(pattern);
    // Null check
    if(value.isEmpty){
        return 'please enter your email';
    }
    // Valid email formatting check
    else if(!regex.hasMatch(value)){
       return 'Enter valid email address';
    }
    // success condition
    else {
       email = value;
    }
    return null;
}

You will be good to go with this :) Happy learning.



来源:https://stackoverflow.com/questions/62659205/how-to-validate-email-before-enter-to-the-home-page-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!