Email validation

I’ve been searching around for a while now and couldn’t find a simple standard email validator to validate an email entry into an input field. Surely there much be a standard solution for this??? Can anyone please advice? Many thanks!

  email: ['', Validators.compose([Validators.maxLength(70), Validators.pattern('^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$'), Validators.required])]
6 Likes

Thanks for your help @dimitri320

1 Like

where to paste this code for email validation?

so first you need to import this stuff:

import { FormBuilder, FormGroup, Validators } from '@angular/forms';

Then you wanna use a form to validate your form inputs:

    this.stripeForm = formBuilder.group({
      email: ['', Validators.compose([Validators.maxLength(70), Validators.pattern('^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$'), Validators.required])]
    });

And then your input:

<ion-input formControlName="email" type="email" [(ngModel)]="email"></ion-input>

1 Like