Soo
Soo

Reputation: 35

How do I validate my email from the first two characters

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.

Upvotes: 2

Views: 77

Answers (2)

Ebube Emeka
Ebube Emeka

Reputation: 262

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

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

Upvotes: 0

Jahidul Islam
Jahidul Islam

Reputation: 12575

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()));
        }

Upvotes: 1

Related Questions