1.0.15 • Published 7 years ago

ng4-validation v1.0.15

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

ng4-validation

A small validator package for Angular 2/4 to validate text field value against a list blacklist words

Template Driven Uses

Import the module in app.module.ts

import { CustomValidationModule } from 'ng4-validation';

This validator need an input which is an array of words named "words". See below how to use

	<input
                            name="organization_name"
                            placeholder=""
                            [(ngModel)] = "organization_name"
                            class="form-control input-md"
                            type="text"
                            formControlName="organization_name"
                            [words]="words"
                            blacklistWords>
                            
	<div
                            *ngIf="contactForm.controls['organization_name'].errors?.blacklistWords"
                            class="alert alert-danger">One of the word is blacklisted
                    </div>

Model Driven Uses

Import the ReactiveFormsModule module in app.module.ts

	import { NgModule } from '@angular/core';
	import { BrowserModule } from '@angular/platform-browser';
	import { ReactiveFormsModule } from '@angular/forms';
	import { AppComponent } from './app.component';
	
	@NgModule({
	imports: [BrowserModule, ReactiveFormsModule],
	declarations: [AppComponent],
	bootstrap: [AppComponent]
	}) 
	
	export class AppModule {}                       

import CustomValidators in app.component.ts or in the app you need to implement

	import { Component } from '@angular/core';
	import { FormGroup, FormControl } from '@angular/forms';
	import { CustomValidators } from 'ng4-validation';
	
	@Component({
	 selector: 'app',
	 template: require('./app.html')
	});
	
	
	export class AppComponent {
	 form: FormGroup;
	 words: any[] = ['this', 'that'];
	 constructor() {
	     this.form = new FormGroup({
	         field: new FormControl('', CustomValidators.blacklistWords(words))
	     });
	 }
	} 
	
	<input  type = "text" name = "firstName" [(ngModel)] = "person.firstName"
	           required>
	  <p *ngIf="demoForm.from.controls.firstName.errors?.blacklistWords">error message</p>

Issues

If you see any issues please create an issue on Github

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago