I'm using TextFormField in Flutter to input email for register page.
What I want is if there's no char '@' and '.' then it will get rejected.
This is the result I hope for :
input : name
errorText : "You should enter valid email address"
input : name@gmail.com
response : success
And this is my code :
TextFormField(
keyboardType: TextInputType.emailAddress,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp("[a-z0-9@._-]")),
],
onChanged: (text) {
_onSearchChanged(text);
},
controller: emailController,
decoration: InputDecoration(
errorText:
isEmailInvalid ? "Email is already taken" : null,
hintText: 'Enter your email',
suffixIcon: isEmailvalid
? const Icon(
Icons.check,
color: Colors.green,
)
: const Icon(
Icons.check_circle,
color: Colors.transparent)
)),