angular - Angular2 email validation pattern not working -


form:

    <div class="group">       <label for="email" class="label">email address</label>       <input id="email" type="text" class="input" name="email" pattern="/^[a-za-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-za-z0-9-]+(?:\.[a-za-z0-9-]+)*$/" [(ngmodel)]="user.email"              #email="ngmodel" required>       <div *ngif="email.errors && (email.dirty || email.touched)" class="alert alert-danger">         <div [hidden]="!email.errors.required">           email invalid         </div>       </div>     </div> 

i tried using regex pattern not woking, doesnt shows error , user created without valid email address. used pattern other angular2 email validation answers stackoverflow.

try this...

if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this.email)){    console.log('valid email'); }else{     console.log('invalid email'); } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -