MrFlutter
MrFlutter

Reputation: 47

how to validate email before enter to the home page flutter

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

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

and this is the code of sign up screen

enter image description here enter image description here

Upvotes: 0

Views: 1246

Answers (1)

Alok
Alok

Reputation: 8998

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.

Upvotes: 2

Related Questions