Facing Problem in validation of email and Phone number in Reactive form












0















I am working on Angular Application where I am facing problem in validation of email and Phone number



Problem




  1. For email validation Problem when I put @ in wrong email and dosen;t put .com or .in example -: abcd@gm .. it dosen't show error message ,


  2. For Phone number validation , error message is only shown when Phone number is left blank , when we enter phone number and it exceed max length or for min leangth then it does not show any error message



I am sharing code here :



component.ts



import { Component, OnInit } from '@angular/core';
import { ServicesService } from '../service/services.service';
import { FormGroup , FormControl , Validators } from '@angular/forms';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.scss']
})
export class RegisterComponent implements OnInit {

constructor( public restapi:ServicesService) {

this.user = new FormGroup({

email: new FormControl('', [Validators.required,Validators.email]),
phone: new FormControl('', [Validators.required, Validators.minLength(10)]),
password: new FormControl('', [Validators.required, Validators.minLength(6)])
});

}
ngOnInit() {


}
}


component.html



 <form class="example-form" novalidate (ngSubmit)='user_signup(user)'  [formGroup]='user'>
<div class="row align-items-center">
<div class="col-md-1">
<label><img src="assets/imgs/email-icon.svg"/></label>
</div>
<div class="col-md-11">
<mat-form-field class="example-full-width">
<input matInput placeholder="Email" name='email' formControlName='email' value="" />
</mat-form-field>
<div style='color:#fff ;float: left ;font-size: 10px;' class="required" no-lines item-end *ngIf="( user.get('email').hasError('required') || user.get('email').hasError('email') ) && user.get('email').touched">
<span class="error" *ngIf="user.get('email').hasError('required') && user.get('email').touched">
Email Required
</span>
<span class="error" *ngIf="user.value.email && user.get('email').hasError('email') && user.get('email').touched">
Invalid email!
</span>
</div>
</div>
</div>
<div class="row align-items-center">
<div class="col-md-1">
<label><img src="assets/imgs/mobile-icon.svg"/></label>
</div>
<div class="col-md-11">

<mat-form-field class="example-full-width" >
<input matInput type='number' placeholder="Phone Number:" name="phone" formControlName="phone" required/>

</mat-form-field>

<div style='color: rgb(248, 226, 226) ; float:left ; font-size: 10px;' class="required" item-end no-lines *ngIf="( user.get('phone').hasError('required') || user.get('phone').hasError('minlength') || user.get('phone').hasError('maxlength'))&& ( user.get('phone').touched)">

<span class="error" *ngIf="user.get('phone').hasError('required') && user.get('phone').touched">
Phone number Required
</span>

<span class="error" *ngIf="user.get('phone').hasError('maxlength') && user.get('phone').touched">
Min 10 digit
</span>

</div>


</div>
</div>

<!--Phone otp-->
<div class="row align-items-center" >
<div class="col-md-1">
<label><img src="assets/imgs/otp-icon.svg"/></label>
</div>
<div class="col-md-9">
<mat-form-field class="example-full-width">
<input matInput placeholder="Verify phone otp:" value="" (input)='onInputTimePhone($event.target.value)' required/>
</mat-form-field>
<div>
<span *ngIf='Otpvarification'> Please enter Otp </span>
</div>
</div>
<div class="col-md-2">
<a class="get_otp" mdbBtn mdbWavesEffect (click)="phoneGetOtp(user.value.phone)">Get otp</a>
</div>
</div>
<!--Phone otp ends-->
<div class="row align-items-center">
<div class="col-md-1">
<label><img src="assets/imgs/password-icon.svg"/></label>
</div>
<div class="col-md-9">
<mat-form-field class="example-full-width">
<input matInput type='{{type}}' placeholder="Password:" name='password' formControlName='password' value="" />
</mat-form-field>
<div style='color: #fff ; float:left ; font-size: 10px;' class="required" text-center no-lines *ngIf="( user.get('password').hasError('required') || user.get('password').hasError('minlength') || user.get('password').hasError('maxlength'))&& user.get('password').touched">
<span class="error" *ngIf="user.get('password').hasError('required') && user.get('password').touched">
Password is required
</span>
<span class="error" *ngIf="user.get('password').hasError('minlength') && user.get('password').touched">
Min 6 characters
</span>
</div>
</div>
<div class="col-md-2">
<a mdbWavesEffect *ngIf="!showPass" (click)="showPassword()" class="showPassword">
<img src="assets/imgs/show.svg" >
</a>
<a mdbWavesEffect *ngIf="showPass" (click)="showPassword()" class="showPassword">
<img src="assets/imgs/hide.svg" >
</a>
</div>

</div>

<button mdb mdbWavesEffect [disabled]="disabledAgreement" class="register_btn">Sign Up</button>
</form>









share|improve this question





























    0















    I am working on Angular Application where I am facing problem in validation of email and Phone number



    Problem




    1. For email validation Problem when I put @ in wrong email and dosen;t put .com or .in example -: abcd@gm .. it dosen't show error message ,


    2. For Phone number validation , error message is only shown when Phone number is left blank , when we enter phone number and it exceed max length or for min leangth then it does not show any error message



    I am sharing code here :



    component.ts



    import { Component, OnInit } from '@angular/core';
    import { ServicesService } from '../service/services.service';
    import { FormGroup , FormControl , Validators } from '@angular/forms';
    @Component({
    selector: 'app-register',
    templateUrl: './register.component.html',
    styleUrls: ['./register.component.scss']
    })
    export class RegisterComponent implements OnInit {

    constructor( public restapi:ServicesService) {

    this.user = new FormGroup({

    email: new FormControl('', [Validators.required,Validators.email]),
    phone: new FormControl('', [Validators.required, Validators.minLength(10)]),
    password: new FormControl('', [Validators.required, Validators.minLength(6)])
    });

    }
    ngOnInit() {


    }
    }


    component.html



     <form class="example-form" novalidate (ngSubmit)='user_signup(user)'  [formGroup]='user'>
    <div class="row align-items-center">
    <div class="col-md-1">
    <label><img src="assets/imgs/email-icon.svg"/></label>
    </div>
    <div class="col-md-11">
    <mat-form-field class="example-full-width">
    <input matInput placeholder="Email" name='email' formControlName='email' value="" />
    </mat-form-field>
    <div style='color:#fff ;float: left ;font-size: 10px;' class="required" no-lines item-end *ngIf="( user.get('email').hasError('required') || user.get('email').hasError('email') ) && user.get('email').touched">
    <span class="error" *ngIf="user.get('email').hasError('required') && user.get('email').touched">
    Email Required
    </span>
    <span class="error" *ngIf="user.value.email && user.get('email').hasError('email') && user.get('email').touched">
    Invalid email!
    </span>
    </div>
    </div>
    </div>
    <div class="row align-items-center">
    <div class="col-md-1">
    <label><img src="assets/imgs/mobile-icon.svg"/></label>
    </div>
    <div class="col-md-11">

    <mat-form-field class="example-full-width" >
    <input matInput type='number' placeholder="Phone Number:" name="phone" formControlName="phone" required/>

    </mat-form-field>

    <div style='color: rgb(248, 226, 226) ; float:left ; font-size: 10px;' class="required" item-end no-lines *ngIf="( user.get('phone').hasError('required') || user.get('phone').hasError('minlength') || user.get('phone').hasError('maxlength'))&& ( user.get('phone').touched)">

    <span class="error" *ngIf="user.get('phone').hasError('required') && user.get('phone').touched">
    Phone number Required
    </span>

    <span class="error" *ngIf="user.get('phone').hasError('maxlength') && user.get('phone').touched">
    Min 10 digit
    </span>

    </div>


    </div>
    </div>

    <!--Phone otp-->
    <div class="row align-items-center" >
    <div class="col-md-1">
    <label><img src="assets/imgs/otp-icon.svg"/></label>
    </div>
    <div class="col-md-9">
    <mat-form-field class="example-full-width">
    <input matInput placeholder="Verify phone otp:" value="" (input)='onInputTimePhone($event.target.value)' required/>
    </mat-form-field>
    <div>
    <span *ngIf='Otpvarification'> Please enter Otp </span>
    </div>
    </div>
    <div class="col-md-2">
    <a class="get_otp" mdbBtn mdbWavesEffect (click)="phoneGetOtp(user.value.phone)">Get otp</a>
    </div>
    </div>
    <!--Phone otp ends-->
    <div class="row align-items-center">
    <div class="col-md-1">
    <label><img src="assets/imgs/password-icon.svg"/></label>
    </div>
    <div class="col-md-9">
    <mat-form-field class="example-full-width">
    <input matInput type='{{type}}' placeholder="Password:" name='password' formControlName='password' value="" />
    </mat-form-field>
    <div style='color: #fff ; float:left ; font-size: 10px;' class="required" text-center no-lines *ngIf="( user.get('password').hasError('required') || user.get('password').hasError('minlength') || user.get('password').hasError('maxlength'))&& user.get('password').touched">
    <span class="error" *ngIf="user.get('password').hasError('required') && user.get('password').touched">
    Password is required
    </span>
    <span class="error" *ngIf="user.get('password').hasError('minlength') && user.get('password').touched">
    Min 6 characters
    </span>
    </div>
    </div>
    <div class="col-md-2">
    <a mdbWavesEffect *ngIf="!showPass" (click)="showPassword()" class="showPassword">
    <img src="assets/imgs/show.svg" >
    </a>
    <a mdbWavesEffect *ngIf="showPass" (click)="showPassword()" class="showPassword">
    <img src="assets/imgs/hide.svg" >
    </a>
    </div>

    </div>

    <button mdb mdbWavesEffect [disabled]="disabledAgreement" class="register_btn">Sign Up</button>
    </form>









    share|improve this question



























      0












      0








      0








      I am working on Angular Application where I am facing problem in validation of email and Phone number



      Problem




      1. For email validation Problem when I put @ in wrong email and dosen;t put .com or .in example -: abcd@gm .. it dosen't show error message ,


      2. For Phone number validation , error message is only shown when Phone number is left blank , when we enter phone number and it exceed max length or for min leangth then it does not show any error message



      I am sharing code here :



      component.ts



      import { Component, OnInit } from '@angular/core';
      import { ServicesService } from '../service/services.service';
      import { FormGroup , FormControl , Validators } from '@angular/forms';
      @Component({
      selector: 'app-register',
      templateUrl: './register.component.html',
      styleUrls: ['./register.component.scss']
      })
      export class RegisterComponent implements OnInit {

      constructor( public restapi:ServicesService) {

      this.user = new FormGroup({

      email: new FormControl('', [Validators.required,Validators.email]),
      phone: new FormControl('', [Validators.required, Validators.minLength(10)]),
      password: new FormControl('', [Validators.required, Validators.minLength(6)])
      });

      }
      ngOnInit() {


      }
      }


      component.html



       <form class="example-form" novalidate (ngSubmit)='user_signup(user)'  [formGroup]='user'>
      <div class="row align-items-center">
      <div class="col-md-1">
      <label><img src="assets/imgs/email-icon.svg"/></label>
      </div>
      <div class="col-md-11">
      <mat-form-field class="example-full-width">
      <input matInput placeholder="Email" name='email' formControlName='email' value="" />
      </mat-form-field>
      <div style='color:#fff ;float: left ;font-size: 10px;' class="required" no-lines item-end *ngIf="( user.get('email').hasError('required') || user.get('email').hasError('email') ) && user.get('email').touched">
      <span class="error" *ngIf="user.get('email').hasError('required') && user.get('email').touched">
      Email Required
      </span>
      <span class="error" *ngIf="user.value.email && user.get('email').hasError('email') && user.get('email').touched">
      Invalid email!
      </span>
      </div>
      </div>
      </div>
      <div class="row align-items-center">
      <div class="col-md-1">
      <label><img src="assets/imgs/mobile-icon.svg"/></label>
      </div>
      <div class="col-md-11">

      <mat-form-field class="example-full-width" >
      <input matInput type='number' placeholder="Phone Number:" name="phone" formControlName="phone" required/>

      </mat-form-field>

      <div style='color: rgb(248, 226, 226) ; float:left ; font-size: 10px;' class="required" item-end no-lines *ngIf="( user.get('phone').hasError('required') || user.get('phone').hasError('minlength') || user.get('phone').hasError('maxlength'))&& ( user.get('phone').touched)">

      <span class="error" *ngIf="user.get('phone').hasError('required') && user.get('phone').touched">
      Phone number Required
      </span>

      <span class="error" *ngIf="user.get('phone').hasError('maxlength') && user.get('phone').touched">
      Min 10 digit
      </span>

      </div>


      </div>
      </div>

      <!--Phone otp-->
      <div class="row align-items-center" >
      <div class="col-md-1">
      <label><img src="assets/imgs/otp-icon.svg"/></label>
      </div>
      <div class="col-md-9">
      <mat-form-field class="example-full-width">
      <input matInput placeholder="Verify phone otp:" value="" (input)='onInputTimePhone($event.target.value)' required/>
      </mat-form-field>
      <div>
      <span *ngIf='Otpvarification'> Please enter Otp </span>
      </div>
      </div>
      <div class="col-md-2">
      <a class="get_otp" mdbBtn mdbWavesEffect (click)="phoneGetOtp(user.value.phone)">Get otp</a>
      </div>
      </div>
      <!--Phone otp ends-->
      <div class="row align-items-center">
      <div class="col-md-1">
      <label><img src="assets/imgs/password-icon.svg"/></label>
      </div>
      <div class="col-md-9">
      <mat-form-field class="example-full-width">
      <input matInput type='{{type}}' placeholder="Password:" name='password' formControlName='password' value="" />
      </mat-form-field>
      <div style='color: #fff ; float:left ; font-size: 10px;' class="required" text-center no-lines *ngIf="( user.get('password').hasError('required') || user.get('password').hasError('minlength') || user.get('password').hasError('maxlength'))&& user.get('password').touched">
      <span class="error" *ngIf="user.get('password').hasError('required') && user.get('password').touched">
      Password is required
      </span>
      <span class="error" *ngIf="user.get('password').hasError('minlength') && user.get('password').touched">
      Min 6 characters
      </span>
      </div>
      </div>
      <div class="col-md-2">
      <a mdbWavesEffect *ngIf="!showPass" (click)="showPassword()" class="showPassword">
      <img src="assets/imgs/show.svg" >
      </a>
      <a mdbWavesEffect *ngIf="showPass" (click)="showPassword()" class="showPassword">
      <img src="assets/imgs/hide.svg" >
      </a>
      </div>

      </div>

      <button mdb mdbWavesEffect [disabled]="disabledAgreement" class="register_btn">Sign Up</button>
      </form>









      share|improve this question
















      I am working on Angular Application where I am facing problem in validation of email and Phone number



      Problem




      1. For email validation Problem when I put @ in wrong email and dosen;t put .com or .in example -: abcd@gm .. it dosen't show error message ,


      2. For Phone number validation , error message is only shown when Phone number is left blank , when we enter phone number and it exceed max length or for min leangth then it does not show any error message



      I am sharing code here :



      component.ts



      import { Component, OnInit } from '@angular/core';
      import { ServicesService } from '../service/services.service';
      import { FormGroup , FormControl , Validators } from '@angular/forms';
      @Component({
      selector: 'app-register',
      templateUrl: './register.component.html',
      styleUrls: ['./register.component.scss']
      })
      export class RegisterComponent implements OnInit {

      constructor( public restapi:ServicesService) {

      this.user = new FormGroup({

      email: new FormControl('', [Validators.required,Validators.email]),
      phone: new FormControl('', [Validators.required, Validators.minLength(10)]),
      password: new FormControl('', [Validators.required, Validators.minLength(6)])
      });

      }
      ngOnInit() {


      }
      }


      component.html



       <form class="example-form" novalidate (ngSubmit)='user_signup(user)'  [formGroup]='user'>
      <div class="row align-items-center">
      <div class="col-md-1">
      <label><img src="assets/imgs/email-icon.svg"/></label>
      </div>
      <div class="col-md-11">
      <mat-form-field class="example-full-width">
      <input matInput placeholder="Email" name='email' formControlName='email' value="" />
      </mat-form-field>
      <div style='color:#fff ;float: left ;font-size: 10px;' class="required" no-lines item-end *ngIf="( user.get('email').hasError('required') || user.get('email').hasError('email') ) && user.get('email').touched">
      <span class="error" *ngIf="user.get('email').hasError('required') && user.get('email').touched">
      Email Required
      </span>
      <span class="error" *ngIf="user.value.email && user.get('email').hasError('email') && user.get('email').touched">
      Invalid email!
      </span>
      </div>
      </div>
      </div>
      <div class="row align-items-center">
      <div class="col-md-1">
      <label><img src="assets/imgs/mobile-icon.svg"/></label>
      </div>
      <div class="col-md-11">

      <mat-form-field class="example-full-width" >
      <input matInput type='number' placeholder="Phone Number:" name="phone" formControlName="phone" required/>

      </mat-form-field>

      <div style='color: rgb(248, 226, 226) ; float:left ; font-size: 10px;' class="required" item-end no-lines *ngIf="( user.get('phone').hasError('required') || user.get('phone').hasError('minlength') || user.get('phone').hasError('maxlength'))&& ( user.get('phone').touched)">

      <span class="error" *ngIf="user.get('phone').hasError('required') && user.get('phone').touched">
      Phone number Required
      </span>

      <span class="error" *ngIf="user.get('phone').hasError('maxlength') && user.get('phone').touched">
      Min 10 digit
      </span>

      </div>


      </div>
      </div>

      <!--Phone otp-->
      <div class="row align-items-center" >
      <div class="col-md-1">
      <label><img src="assets/imgs/otp-icon.svg"/></label>
      </div>
      <div class="col-md-9">
      <mat-form-field class="example-full-width">
      <input matInput placeholder="Verify phone otp:" value="" (input)='onInputTimePhone($event.target.value)' required/>
      </mat-form-field>
      <div>
      <span *ngIf='Otpvarification'> Please enter Otp </span>
      </div>
      </div>
      <div class="col-md-2">
      <a class="get_otp" mdbBtn mdbWavesEffect (click)="phoneGetOtp(user.value.phone)">Get otp</a>
      </div>
      </div>
      <!--Phone otp ends-->
      <div class="row align-items-center">
      <div class="col-md-1">
      <label><img src="assets/imgs/password-icon.svg"/></label>
      </div>
      <div class="col-md-9">
      <mat-form-field class="example-full-width">
      <input matInput type='{{type}}' placeholder="Password:" name='password' formControlName='password' value="" />
      </mat-form-field>
      <div style='color: #fff ; float:left ; font-size: 10px;' class="required" text-center no-lines *ngIf="( user.get('password').hasError('required') || user.get('password').hasError('minlength') || user.get('password').hasError('maxlength'))&& user.get('password').touched">
      <span class="error" *ngIf="user.get('password').hasError('required') && user.get('password').touched">
      Password is required
      </span>
      <span class="error" *ngIf="user.get('password').hasError('minlength') && user.get('password').touched">
      Min 6 characters
      </span>
      </div>
      </div>
      <div class="col-md-2">
      <a mdbWavesEffect *ngIf="!showPass" (click)="showPassword()" class="showPassword">
      <img src="assets/imgs/show.svg" >
      </a>
      <a mdbWavesEffect *ngIf="showPass" (click)="showPassword()" class="showPassword">
      <img src="assets/imgs/hide.svg" >
      </a>
      </div>

      </div>

      <button mdb mdbWavesEffect [disabled]="disabledAgreement" class="register_btn">Sign Up</button>
      </form>






      angular angular5 angular6 angular-reactive-forms






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 6:43







      Testing Anurag

















      asked Jan 3 at 3:35









      Testing AnuragTesting Anurag

      8610




      8610
























          3 Answers
          3






          active

          oldest

          votes


















          0















          1. That's correct actually, test@test can be a valid email.

          2. It's minlength, not minLength






          share|improve this answer
























          • for 2. I am getting error implementing minlength error ==>> Property 'minlength' does not exist on type 'typeof Validators'. Did you mean 'minLength'?ts(2551)

            – Testing Anurag
            Jan 3 at 4:56



















          0














          try this way



          this.user = new FormGroup({

          email: new FormControl('', [Validators.required,Validators.email]),
          phone: new FormControl('', [Validators.required, Validators.pattern("[0-9]{0-10}")]),
          password: new FormControl('', [Validators.required, Validators.minLength(6)])
          });


          I have applied pattern for phone number validation.






          share|improve this answer































            0














            Why don't you use Validators.pattern



            emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$";
            phoneNumber = "^(+d{1,3}[- ]?)?d{10}$";
            this.user = new FormGroup(
            email: new FormControl('', [Validators.required, Validators.pattern(this.emailPattern)]),
            phone: new FormControl('', [Validators.required, Validators.pattern(this.phoneNumber)]),
            password: new FormControl('', [Validators.required, Validators.minLength(6)])
            });


            EDIT:
            refer to this link for more details






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016008%2ffacing-problem-in-validation-of-email-and-phone-number-in-reactive-form%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0















              1. That's correct actually, test@test can be a valid email.

              2. It's minlength, not minLength






              share|improve this answer
























              • for 2. I am getting error implementing minlength error ==>> Property 'minlength' does not exist on type 'typeof Validators'. Did you mean 'minLength'?ts(2551)

                – Testing Anurag
                Jan 3 at 4:56
















              0















              1. That's correct actually, test@test can be a valid email.

              2. It's minlength, not minLength






              share|improve this answer
























              • for 2. I am getting error implementing minlength error ==>> Property 'minlength' does not exist on type 'typeof Validators'. Did you mean 'minLength'?ts(2551)

                – Testing Anurag
                Jan 3 at 4:56














              0












              0








              0








              1. That's correct actually, test@test can be a valid email.

              2. It's minlength, not minLength






              share|improve this answer














              1. That's correct actually, test@test can be a valid email.

              2. It's minlength, not minLength







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 3 at 4:14









              ChristianChristian

              1,168714




              1,168714













              • for 2. I am getting error implementing minlength error ==>> Property 'minlength' does not exist on type 'typeof Validators'. Did you mean 'minLength'?ts(2551)

                – Testing Anurag
                Jan 3 at 4:56



















              • for 2. I am getting error implementing minlength error ==>> Property 'minlength' does not exist on type 'typeof Validators'. Did you mean 'minLength'?ts(2551)

                – Testing Anurag
                Jan 3 at 4:56

















              for 2. I am getting error implementing minlength error ==>> Property 'minlength' does not exist on type 'typeof Validators'. Did you mean 'minLength'?ts(2551)

              – Testing Anurag
              Jan 3 at 4:56





              for 2. I am getting error implementing minlength error ==>> Property 'minlength' does not exist on type 'typeof Validators'. Did you mean 'minLength'?ts(2551)

              – Testing Anurag
              Jan 3 at 4:56













              0














              try this way



              this.user = new FormGroup({

              email: new FormControl('', [Validators.required,Validators.email]),
              phone: new FormControl('', [Validators.required, Validators.pattern("[0-9]{0-10}")]),
              password: new FormControl('', [Validators.required, Validators.minLength(6)])
              });


              I have applied pattern for phone number validation.






              share|improve this answer




























                0














                try this way



                this.user = new FormGroup({

                email: new FormControl('', [Validators.required,Validators.email]),
                phone: new FormControl('', [Validators.required, Validators.pattern("[0-9]{0-10}")]),
                password: new FormControl('', [Validators.required, Validators.minLength(6)])
                });


                I have applied pattern for phone number validation.






                share|improve this answer


























                  0












                  0








                  0







                  try this way



                  this.user = new FormGroup({

                  email: new FormControl('', [Validators.required,Validators.email]),
                  phone: new FormControl('', [Validators.required, Validators.pattern("[0-9]{0-10}")]),
                  password: new FormControl('', [Validators.required, Validators.minLength(6)])
                  });


                  I have applied pattern for phone number validation.






                  share|improve this answer













                  try this way



                  this.user = new FormGroup({

                  email: new FormControl('', [Validators.required,Validators.email]),
                  phone: new FormControl('', [Validators.required, Validators.pattern("[0-9]{0-10}")]),
                  password: new FormControl('', [Validators.required, Validators.minLength(6)])
                  });


                  I have applied pattern for phone number validation.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 3 at 6:54









                  Sachin ShahSachin Shah

                  1,7561516




                  1,7561516























                      0














                      Why don't you use Validators.pattern



                      emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$";
                      phoneNumber = "^(+d{1,3}[- ]?)?d{10}$";
                      this.user = new FormGroup(
                      email: new FormControl('', [Validators.required, Validators.pattern(this.emailPattern)]),
                      phone: new FormControl('', [Validators.required, Validators.pattern(this.phoneNumber)]),
                      password: new FormControl('', [Validators.required, Validators.minLength(6)])
                      });


                      EDIT:
                      refer to this link for more details






                      share|improve this answer




























                        0














                        Why don't you use Validators.pattern



                        emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$";
                        phoneNumber = "^(+d{1,3}[- ]?)?d{10}$";
                        this.user = new FormGroup(
                        email: new FormControl('', [Validators.required, Validators.pattern(this.emailPattern)]),
                        phone: new FormControl('', [Validators.required, Validators.pattern(this.phoneNumber)]),
                        password: new FormControl('', [Validators.required, Validators.minLength(6)])
                        });


                        EDIT:
                        refer to this link for more details






                        share|improve this answer


























                          0












                          0








                          0







                          Why don't you use Validators.pattern



                          emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$";
                          phoneNumber = "^(+d{1,3}[- ]?)?d{10}$";
                          this.user = new FormGroup(
                          email: new FormControl('', [Validators.required, Validators.pattern(this.emailPattern)]),
                          phone: new FormControl('', [Validators.required, Validators.pattern(this.phoneNumber)]),
                          password: new FormControl('', [Validators.required, Validators.minLength(6)])
                          });


                          EDIT:
                          refer to this link for more details






                          share|improve this answer













                          Why don't you use Validators.pattern



                          emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$";
                          phoneNumber = "^(+d{1,3}[- ]?)?d{10}$";
                          this.user = new FormGroup(
                          email: new FormControl('', [Validators.required, Validators.pattern(this.emailPattern)]),
                          phone: new FormControl('', [Validators.required, Validators.pattern(this.phoneNumber)]),
                          password: new FormControl('', [Validators.required, Validators.minLength(6)])
                          });


                          EDIT:
                          refer to this link for more details







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 3 at 6:55









                          Abhishek EkaanthAbhishek Ekaanth

                          1,1461125




                          1,1461125






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016008%2ffacing-problem-in-validation-of-email-and-phone-number-in-reactive-form%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Mossoró

                              Error while reading .h5 file using the rhdf5 package in R

                              Pushsharp Apns notification error: 'InvalidToken'