Home > Mobile >  How do I validate my email from the first two characters
How do I validate my email from the first two characters

Time:10-14

How do I validate my email from the first two characters to allow different email access to specific pages?

Now I only know use " if " to validate my email. I want to know how to validate email, for example the first two character " 12 " go to the " Home " and " 43 " go to " Home2 "

    if (googleUser.email == '[email protected]') {
          Navigator.push(context, MaterialPageRoute(builder: (context) => Home()));
        } else if (googleUser.email == '[email protected]') {
          Navigator.push(context, MaterialPageRoute(builder: (context) => Home2()));
        }

Please guide me on this.

CodePudding user response:

Let's try

if (googleUser.email.startsWith('12')) {
          Navigator.push(context, MaterialPageRoute(builder: (context) => Home()));
        } else if (googleUser.email.startsWith('43')) {
          Navigator.push(context, MaterialPageRoute(builder: (context) => Home2()));
        }

CodePudding user response:

use startsWith method. It's a dart method. So you could do something like

if(email.startsWith('43')){
//do here
}
  • Related