-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from Nightapes/email-validation
Email validation
- Loading branch information
Showing
19 changed files
with
736 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/src/app/email-validator/form/email/form-email.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<form> | ||
<mat-form-field> | ||
<input type="email" matInput [(ngModel)]="model" name="email" #formControl="ngModel" email placeholder="Email"> | ||
<mat-hint *ngIf="formControl.hasError('normalEmailRule')" class="error">Needs to be a number</mat-hint> | ||
<mat-hint *ngIf="formControl.hasError('normalEmailRule')" class="error">Is not a email</mat-hint> | ||
</mat-form-field> | ||
</form> |
6 changes: 6 additions & 0 deletions
6
examples/src/app/email-validator/form/suggest/form-email-suggest.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<form> | ||
<mat-form-field> | ||
<input type="email" matInput [(ngModel)]="model" name="email" #formControl="ngModel" [emailSuggest]="customOptions" placeholder="Email"> | ||
<mat-hint *ngIf="formControl.hasError('suggestion')" class="error"> <span>Did you mean:</span><span class="clickable" (click)="addToForm(formControl.getError('suggestion').full)">{{formControl.getError('suggestion').domain}}</span> </mat-hint> | ||
</mat-form-field> | ||
</form> |
34 changes: 34 additions & 0 deletions
34
examples/src/app/email-validator/form/suggest/form-email-suggest.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component } from '@angular/core'; | ||
import { EmailOptions } from 'ngx-validators/components/email/email-util'; | ||
|
||
@Component({ | ||
selector: 'app-email-suggest', | ||
templateUrl: './form-email-suggest.component.html' | ||
}) | ||
|
||
export class FormEmailSuggestComponent { | ||
model: any; | ||
|
||
// Add your own domains via EmailOptions | ||
customOptions: EmailOptions = { | ||
domains: ['msn.com', 'bellsouth.net', | ||
'telus.net', 'comcast.net', 'optusnet.com.au', | ||
'earthlink.net', 'qq.com', 'sky.com', 'icloud.com', | ||
'mac.com', 'sympatico.ca', 'googlemail.com', | ||
'att.net', 'xtra.co.nz', 'web.de', 'mymail.com', | ||
'cox.net', 'gmail.com', 'ymail.com', 'yahoo.com', | ||
'aim.com', 'rogers.com', 'verizon.net', | ||
'rocketmail.com', 'google.com', 'optonline.net', | ||
'sbcglobal.net', 'aol.com', 'me.com', 'btinternet.com', | ||
'charter.net', 'shaw.ca'], | ||
secondLevelDomains: ['yahoo', 'hotmail', 'mail', 'live', 'outlook', 'gmx', 'mymail'], | ||
topLevelDomains: ['com', 'com.au', 'com.tw', 'ca', 'co.nz', 'co.uk', 'de', | ||
'fr', 'it', 'ru', 'net', 'org', 'edu', 'gov', 'jp', 'nl', 'kr', 'se', 'eu', | ||
'ie', 'co.il', 'us', 'at', 'be', 'dk', 'hk', 'es', 'gr', 'ch', 'no', 'cz', | ||
'in', 'net', 'net.au', 'info', 'biz', 'mil', 'co.jp', 'sg', 'hu', 'uk'] | ||
}; | ||
|
||
addToForm(email) { | ||
this.model = email; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
.../src/app/email-validator/reactive-form/suggest/reactive-form-email-suggest.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<form [formGroup]="form"> | ||
<mat-form-field> | ||
<input matInput formControlName="email" name="email" placeholder="Email"> | ||
<mat-hint *ngIf="email.hasError('suggestion')" class="error"> <span>Did you mean:</span><span class="clickable" (click)="addToForm(email.getError('suggestion').full)">{{email.getError('suggestion').domain}}</span> </mat-hint> | ||
</mat-form-field> | ||
</form> |
43 changes: 43 additions & 0 deletions
43
...es/src/app/email-validator/reactive-form/suggest/reactive-form-email-suggest.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; | ||
import { EmailValidators } from 'ngx-validators'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { EmailOptions } from 'ngx-validators/components/email/email-util'; | ||
|
||
@Component({ | ||
selector: 'app-reactive-email-suggest', | ||
templateUrl: './reactive-form-email-suggest.component.html' | ||
}) | ||
export class ReactiveFormEmailSuggestComponent implements OnInit { | ||
|
||
// Add your own domains via EmailOptions | ||
customOptions: EmailOptions = { | ||
domains: ['msn.com', 'bellsouth.net', | ||
'telus.net', 'comcast.net', 'optusnet.com.au', | ||
'earthlink.net', 'qq.com', 'sky.com', 'icloud.com', | ||
'mac.com', 'sympatico.ca', 'googlemail.com', | ||
'att.net', 'xtra.co.nz', 'web.de', | ||
'cox.net', 'gmail.com', 'ymail.com', 'yahoo.com', | ||
'aim.com', 'rogers.com', 'verizon.net', | ||
'rocketmail.com', 'google.com', 'optonline.net', | ||
'sbcglobal.net', 'aol.com', 'me.com', 'btinternet.com', | ||
'charter.net', 'shaw.ca'], | ||
secondLevelDomains: ['yahoo', 'hotmail', 'mail', 'live', 'outlook', 'gmx'], | ||
topLevelDomains: ['com', 'com.au', 'com.tw', 'ca', 'co.nz', 'co.uk', 'de', | ||
'fr', 'it', 'ru', 'net', 'org', 'edu', 'gov', 'jp', 'nl', 'kr', 'se', 'eu', | ||
'ie', 'co.il', 'us', 'at', 'be', 'dk', 'hk', 'es', 'gr', 'ch', 'no', 'cz', | ||
'in', 'net', 'net.au', 'info', 'biz', 'mil', 'co.jp', 'sg', 'hu', 'uk'] | ||
}; | ||
form: FormGroup; | ||
email = new FormControl('', Validators.compose([EmailValidators.suggest(this.customOptions)])); | ||
constructor(protected _fb: FormBuilder) { } | ||
|
||
ngOnInit() { | ||
this.form = this._fb.group({ | ||
'email': this.email, | ||
}); | ||
} | ||
|
||
addToForm(email) { | ||
this.form.get('email').setValue(email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.