validation - Angular2: Validate email address inside md-input -


i have angular2 form md-input element inside:

<form  novalidate (ngsubmit)="onsubmit(resetpasswfg)" [formgroup]="resetpasswfg" style="width:400px;border:1px solid black; ">   <table style="width:400px;">     <tr>       <td>         <md-input  class="input" mdinput placeholder="email" type="email" formcontrolname="email">           <md-hint class="input_error" *ngif="resetpasswfg.get('email').haserror('required') && resetpasswfg.get('email').touched">             email required           </md-hint>         </md-input>       </td>     </tr> <!-- other elements --> </form> 

and validator inside component:

ngoninit() {     this.resetpasswfg = new formgroup({       email: new formcontrol('', [validators.required, validators.required ])     }) } 

now, if email field not populator, md-hint appear correctly. md-hint appear if email md-input doesn't contain formed email address. how can do?

you can use email validator via directive. see emailvalidator class.

a directive adds email validator controls marked email attribute, via ng_validators binding.


<md-input  class="input" mdinput placeholder="email" type="email" formcontrolname="email" email> 

the directive available in package ng2-validators.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -