1

This question maybe exist multiple times but I tried googling for it and try it out but it won't work in my case.

I have a FormBuilder with an email input in my Ionic 3 App

This is my Validators in my formBuilder for email.

 email: [
        "",
        Validators.compose([
          Validators.pattern(`/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/`),
          Validators.required
        ])
      ],

I found this regEx right here.

In my html code

    <ion-input formControlName="email" type="email" placeholder="E-mail Address *"></ion-input>
  <validation-messages *ngIf="form.controls['email'].errors.pattern" [message]="'This is not a valid E-mail address'"></validation-messages> // Component validator message

When I still able to type a correct email address it sais that it is incorrect for example.

testing@gmail.com // Not a valid email

I had also tried this regEx pattern below:

^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$

This one works but if I tried to input:

testing@gmail // Valid email which it should be not. Need to use .com .org or any that starts with a dot after the @domain

I knew this is just a simple question.

But can't find the proper solution.

Appreciate if someone could help Thanks in advance.

KnowledgeSeeker
  • 1,058
  • 2
  • 19
  • 44

0 Answers0