ngx-ow
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

ngx-ow Build Status

Angular form validation on steroids

Use Ow to easily validate your Angular forms.

Install

$ npm install ow ngx-ow

Usage

Ow API documentation - Example

import {Component, OnInit} from '@angular/core';
import {owValidator} from 'ngx-ow';
import ow from 'ow';

@Component({
	selector: 'sign-up',
	templateUrl: 'sign-up.component.html'
})
export class SignUpComponent implements OnInit {
	form: FormGroup;

	constructor(
		private formBuilder: FormBuilder
	) {}

	ngOnInit() {
		this.form = this.formBuilder.group({
			firstName: ['', owValidator('firstNameRequired', ow.string.nonEmpty)],
			name: ['', owValidator('nameRequired', ow.string.nonEmpty)],
			email: ['', owValidator('emailInvalid', ow.string.nonEmpty.includes('@'))],
			password: ['', owValidator('passwordInvalid', ow.string.minLength(6))]
		});
	}
}

If someone enters an invalid email address, the errors object for the email control will look like this.

{
	"emailInvalid": "Expected string to include `@`, got `hello`"
}

Related

  • ow - Function argument validation for humans.

License

MIT © Sam Verschueren

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.00latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.00
0.1.02

Package Sidebar

Install

npm i ngx-ow

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

28.8 kB

Total Files

21

Last publish

Collaborators

  • samverschueren