Angular2 email validation

前端 未结 9 1872
既然无缘
既然无缘 2020-12-13 04:20

I am new in learning Angular2, and I want to make a validation form that verifies emails after a RegEx pattern.

My code looks something like this but I don\'t have a

相关标签:
9条回答
  • 2020-12-13 04:32

    You can use this pattern for your email inputs:

    ^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$
    

    ref

    This pattern accepts "sample@domain" also in addition of "sample@domain.dom". Using this email pattern "sample@domain." is not acceptable and 1 letter domain tld is not allowed ("sample@domain.s" goes wrong).

    0 讨论(0)
  • 2020-12-13 04:35

    This pattern worked for me which will accept alphanumeric characters and '.' special character.

    ^[\\w]+(?:\\.[\\w])*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$
    
    0 讨论(0)
  • 2020-12-13 04:37

    Try This One it will work:

    ^[a-zA-Z]+([.-]?[a-zA-Z0-9]+)*@([a-zA-Z]+([.-]?[a-zA-Z]))[.]{1}[a-zA-Z]{2,}$
    
    0 讨论(0)
  • 2020-12-13 04:42

    Angular 4 Email Validation :

    • Use email to your input
    • If you want .com for email use pattern pattern="[a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}

    Final :

    `<input type="email" [(ngModel)]="enterEmail" name="myEmail" #myEmail="ngModel" email pattern="[a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}" required>`
    
    0 讨论(0)
  • 2020-12-13 04:42

    this pattern email working :

     <input  pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$">
    
    0 讨论(0)
  • 2020-12-13 04:44

    Try Something like that

    <div class="alert-email">
            <label>Email</label>
                <input
                    id="contactemail"
                    type="text"                
                    #contactemail="ngModel"
                    [(ngModel)]="model.contactemail"
                    required
                    pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$">
    
            <div class="md-errors-spacer" [hidden]="contactemail.valid || contactemail.untouched">
                <div  *ngIf="contactemail.errors && contactemail.errors.required">
                    Email is required
                </div>
                <div  *ngIf="contactemail.errors && contactemail.errors.pattern">
                    Email is invalid
                </div>
            </div>
        </div>
    
    0 讨论(0)
提交回复
热议问题