How to validate URL Pattern in Angular?

Today, We want to share with you How to validate URL Pattern in Angular?.In this post we will show you URL Pattern Validation in Angular, hear for alphanumeric validation in angular 7 we will give you demo and example for implement.In this post, we will learn about Angular 6 Forms Validation Example – [Required, Email, URL, Dropdown and Min-Max min-length] with an example.

How to validate URL Pattern in Angular?

There are the Following The simple About angular 2 password validation pattern Full Information With Example and source code.

As I will cover this Post with live Working example to develop url validation angular 7, so the angular 2 input url validation is used for this example is following below.

Read Also:  Learn Angular 5 from Scratch - angular 5 Tutorial

Angular is a platform for building mobile & desktop web Based user friendly and light weight applications.Angular,It’s TypeScript-based open-source Angularjs web application framework.

Keywords :

URL Pattern Validation in Angular

Solution:


const reg = '(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?';
this.form = fb.group({

  url: ['', [Validators.required, Validators.pattern(reg)]]

})

src/app/app.component.html

<div class="wrap jdk-form container">
    <h1>URL Validation in Angular - Pakainfo.com.com</h1>
        
    <form [formGroup]="form" (ngSubmit)="submit()">
           
        <div class="form-group">
            <label for="url">URL</label>
            <input 
                formControlName="url"
                id="url" 
                type="text" 
                class="form-control dsp">
            <div *ngIf="f.url.touched && f.url.invalid" class="alert alert-danger">
                <div *ngIf="f.url.errors.required">URL is required.</div>
                <div *ngIf="f.url.errors.pattern">Please enter valid url.</div>
            </div>
        </div>
       
        <button class="btn btn-success" type="submit" [disabled]="!form.valid">Submit</button>
    </form>
</div>

src/app/app.component.ts

import { Component } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators} from '@angular/forms';
    
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  form: FormGroup = new FormGroup({});
   
  constructor(private fb: FormBuilder) {
    const reg = '(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?';
    this.form = fb.group({
      url: ['', [Validators.required, Validators.pattern(reg)]]
    })
  }
    
  get f(){
    return this.form.controls;
  }
   
  submit(){
    console.log(this.form.value);
  }
   
}

Web Programming Tutorials Example with Demo

Read :

Read Also:  Check if Checkbox Checked Unchecked using Angular Example

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about angular 5/6/7 password validation pattern.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.