Today, We want to share with you Angular 6 Form Validation Tutorial Example From Scratch.
In this post we will show you Form Validation in Angular 6 with Example, hear for Angular 6 form validation on submit example we will give you demo and example for implement.
In this post, we will learn about with an example.
Angular 6 Form Validation Tutorial Example From Scratch
There are the Following The simple About Angular 6 Form Validation Tutorial with Email validator Full Information With Example and source code.
This is a quick Lovely Post of how to setup first simple HTML form validation in Angular 6 using get Data form-validation.with Custom CSS of the simple example is all done with latest version of the Bootstrap 4 CSS.
Angular 6 Example
Angular Latest My Previous Post With Source code Read more…..
- Angular 6 Folder Project Structure
- Angular 6 CLI Installation
- Angular 6 Module File
- Angular 6 Components
- Angular 6 Services
- Angular 6 Routing
- Angular 6 CSS
- Angular 6 Class Binding
- Angular 6 Animation
- Angular 6 Templating
- Angular 6 HTTP Client
Template-driven validation
template/student-form-template.component.html
<input id="uname" name="uname" class="pakainfo form-control" required minlength="4" appcustomNameForBidden="birthdate" [(ngModel)]="student.name" #name="ngModel" > <div *ngIf="uname.invalid && (uname.dirty || uname.touched)" class="alert alert-danger"> <div *ngIf="uname.errors.required"> UserName is required. </div> <div *ngIf="uname.errors.minlength"> UserName must be at least 5 characters long. </div> <div *ngIf="uname.errors.customNameForBidden"> UserName cannot be This birthdate. </div> </div>
angular 6 Reactive form validation
reactive/student-form-reactive.component.ts (validator functions)
ngOnInit(): void { this.studentForm = new FormGroup({ 'uname': new FormControl(this.student.uname, [ Validators.required, Validators.minLength(5), customNameForBiddenValidator(/birthdate/i) // ]), 'alterEgo': new FormControl(this.student.alterEgo), 'power': new FormControl(this.student.power, Validators.required) }); } get uname() { return this.studentForm.get('uname'); } get power() { return this.studentForm.get('power'); }
reactive/student-form-reactive.component.html (uname with error msg)
<input id="uname" class="form-control" formControlName="uname" required > <div *ngIf="uname.invalid && (uname.dirty || uname.touched)" class="alert alert-danger"> <div *ngIf="uname.errors.required"> UserName is required. </div> <div *ngIf="uname.errors.minlength"> UserName must be Min 5 characters long. </div> <div *ngIf="uname.errors.customNameForBidden"> UserName cannot be birthdate. </div> </div>
Angular 6 Custom validators
shared/forbidden-name.directive.ts
export function customCLLForBiddenNameValidator(nameRe: RegExp): ValidatorFn { return (control: AbstractControl): {[key: string]: any} | null => { const dataforget = nameRe.test(control.value); return dataforget ? {'customNameForBidden': {value: control.value}} : null; }; }
- Angular 6 applications β Insert, Fetch , Edit β update , Delete Operations
- Angular 6 CRUD
- Angular 6 and ASP.NET Core 2.0 Web API
- Angular 6 features
- Angular 6 Form Validation
- Angular 6 β User Registration and Login
- Angularjs 6 User Registration and Login Authentication
- Angular 6 CLI Installation Tutorial With Example
- Angular 6 Toast Message Notifications From Scratch
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about angular 6 reactive forms validation.
I would like to have feedback on my Pakainfo.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.