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.

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


URL Validation in Angular - Pakainfo.com.com

URL is required.
Please enter valid url.

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 :

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.

Leave a Comment