0

I am working on a form ,I have two fields contact number and alternate contact number. My aim is if the value entered in alternate contact number matches with contact number then it should push.msg "please change number".I tried ngModel and onchange event but that dosen't seem to work.

html

   <div class="ui-g-12 ui-md-6">
                    <div class="ui-g-12 ui-md-6 ui-md-nopad ui-g-nopad">Mobile Number<span style="color:red">*</span>
                    </div>
                    <div class="ui-g-12 ui-md-6 ui-md-nopad ui-g-nopad">
                        <p-inputMask  mask="9999999999" placeholder="Contact No." formControlName='Proposercontact'>
                        </p-inputMask>
                    </div>
                </div>

 <div class="ui-g-12 ui-md-6">
                    <div class="ui-g-12 ui-md-6 ui-md-nopad ui-g-nopad">Alternate Contact no<span
                            style="color:red">*</span>
                    </div>

                    <div class="ui-g-12 ui-md-6 ui-md-nopad ui-g-nopad">
                        <p-inputMask mask="9999999999" placeholder="Contact No." formControlName='Proposercontact1'>
                        </p-inputMask>
                    </div>
                </div>
1
  • At what event you want to show the message? As and when the user types or when the form is submitted? Commented Apr 16, 2021 at 9:36

2 Answers 2

3

How you put ngModel? Should be like this:

In your component.html:

<p-inputMask  mask="9999999999" placeholder="Contact No." [(ngModel)]="contactNo">
</p-inputMask>

In your component.ts:

contactNo: string;

You can refer to this PrimeNG StackBlitz example

Sign up to request clarification or add additional context in comments.

Comments

0

If you would to use Reactive Forms with your project , by injecting

<div class="ui-g-12 ui-md-6" [formGroup]="nameForm">
                    <div class="ui-g-12 ui-md-6 ui-md-nopad ui-g-nopad">Alternate Contact no<span
                            style="color:red">*</span>
                    </div>

                    <div class="ui-g-12 ui-md-6 ui-md-nopad ui-g-nopad">
                        <p-inputMask mask="9999999999" placeholder="Contact No." formControlName='Proposercontact1'>
                        </p-inputMask>
                    </div>
                </div>

And you should define the FormGroup instance in your ts code :

import { Component, OnInit, ViewChild } from '@angular/core';
import { AbstractControl, FormBuilder, FormControl, FormGroup } from '@angular/forms';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  public nameForm:FormGroup;
  myusername: string = "";
  constructor( private formBuilder: FormBuilder) {
    this.nameForm = this.formBuilder.group({
      Proposercontact1: ''
    });
  }
  
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.