Form Validation in Ionic 6 with Reactive Forms

In this Angular Ionic Forms Validation tutorial, we will see how to validate forms in Ionic using Reactive Forms.

Any application is incomplete without implementing forms; forms make the communication between user and server through data transmission.

Reactive Forms helps you efficiently build the Forms; you can implement input level validation with it too.

Reactive forms provide a model-driven approach to handling form inputs whose values change over time.

There are two methods to handle forms in Angular Ionic, template-driven and reactive forms.

In this tutorial, we will use Reactive forms to build and validate forms. We will also create an Ionic app from scratch and add validation rules for the name, email, date of birth, and phone number.

Let’s get started.

Create Ionic App

Let’s create Ionic app:

ionic start ionic-form-validation-example blank --type=angular

Get into the project root.

cd ionic-form-validation-example

To test the app install lab mode:

npm i @ionic/lab --save-dev

Remove Type Errors

You have to remove strict type errors make sure to set “strictTemplates”: false in angularCompilerOptions in tsconfig.json file.

Import ReactiveFormsModule in Ionic

Import angular’s ReactiveFormsModule and FormsModule APIs in home.module.ts file, It allows you to create the Form in Ionic.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';

import { HomePage } from './';

  imports: [
        path: '',
        component: HomePage
  declarations: [HomePage]

export class HomePageModule { }

Validate Form in Ionic

Reactive forms offers better control for handling forms, we are creating and validating Forms in Ionic application.

So, add the following code in file:

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from "@angular/forms";

  selector: 'app-home',
  templateUrl: '',
  styleUrls: [''],

export class HomePage implements OnInit {
  myForm: FormGroup;
  submitted = false;

  constructor(public formBuilder: FormBuilder) { }

  ngOnInit() {
    this.myForm ={
      name: ['', [Validators.required, Validators.minLength(3)]],
      email: ['', [Validators.required, Validators.pattern('[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$')]],
      dob: [],
      phone: ['', [Validators.required, Validators.pattern('^[0-9]+$')]]

  fetchDate(e) {
    let date = new Date(, 10);
    this.myForm.get('dob').setValue(date, {
      onlyself: true

  get errorCtr() {
    return this.myForm.controls;

  onSubmit() {
    this.submitted = true;
    if (!this.myForm.valid) {
      console.log('All fields are required.')
      return false;
    } else {

Place the following code in

    <ion-title>Ionic Forms</ion-title>

  <form [formGroup]="myForm" (ngSubmit)="onSubmit()" novalidate>

    <ion-item lines="full">
      <ion-label position="floating">Name</ion-label>
      <ion-input formControlName="name" type="text"></ion-input>
    <span class="error ion-padding" *ngIf="submitted &&">
      Name is required.
    <span class="error ion-padding" *ngIf="submitted &&">
      Min 3 chars long.

    <ion-item lines="full">
      <ion-label position="floating">Email</ion-label>
      <ion-input formControlName="email" type="email"></ion-input>
    <span class="error ion-padding" *ngIf="submitted &&">
      Email is required.
    <span class="error ion-padding" *ngIf="submitted &&">
      Enter valid email.

    <ion-item lines="full">
      <ion-label position="floating">DOB</ion-label>
      <ion-datetime (ionChange)="fetchDate($event)" formControlName="dob" [value]="defaultDate"></ion-datetime>

    <ion-item lines="full">
      <ion-label position="floating">Phone</ion-label>
      <ion-input maxlength="10" formControlName="phone" type="text" required></ion-input>
    <span class="error ion-padding" *ngIf="submitted &&">
      Phone number is required.
    <span class="error ion-padding" *ngIf="submitted &&">
      Number values allowed.

        <ion-button type="submit" color="danger" expand="block">Submit</ion-button>

Run Ionic Form Application

Start the Ionic form validation app.

ionic serve -l

Form Validation in Ionic with Reactive Forms

Download the full code of this tutorial from GitHub.