I'm developing a new Angular based application, with a login form based on email and password.
It have a form for these fields, defined by the following lines:
let formConfig = {
email: ['', [Validators.required, Validators.email]],
password: ['', [Validators.required]],
};
this.form = this.formBuilder.group(formConfig)
It works just as expected, except for one situation:
When the user uses Samsung's (and others) autocompletes to fill the email field, it inserts an empty space after the email, and the Validators.email assumes that it's an invalid email.
My question is how can I solve this particular situation?
I'm pretty sure that I can just put some existing email validation regex, but I hate to reinvent the wheel, if the validator exists, creating another one looks crazy.
It's possible to implement some kind of validator that modifies my form control value stripping out whitespaces?
I experienced the same.
For everyone still encountering this issue;
adding type="email" to your <input> in combinitation with Validators.email should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With