1

I am using form field validator, I think it will be the same if using normal TextField, and I have form field like this

  TextFormField(  
    onChanged: (val) => selectedEmail = val,  
    validator: EmailValidator(errorText: "Email is not valid"),  
  )  

unfortunately, my user sometimes unintentionally will put an empty string at the end of email string like this :

"[email protected] "

as you can see, I have email validator here, but the email validator will consider the string with empty space like that as an invalid email.

I want to remove or trim the email string first before it is validated by the EmailValidator, how to do that?

1
  • Did you try string.trim()? Commented Sep 21, 2022 at 4:34

2 Answers 2

1
  TextFormField(  
    onChanged: (val) => selectedEmail = val,  
    validator: EmailValidator(errorText: "Email is not valid"),  
        inputFormatters: [FilteringTextInputFormatter.deny(RegExp(r'\s'))]

  ) 

FilteringTextInputFormatter.deny(RegExp(r'\s')) it's deny white space in the TextFormField

Sign up to request clarification or add additional context in comments.

Comments

0

It could be helpful.

TextFormField(  
    onChanged: (val) => selectedEmail.trim() = val.trim(),  
    validator: EmailValidator(errorText: "Email is not valid"),  
  )  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.