@runninghill/ng-rsa-form-validators
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Runninghill Logo

Angular South African Form Validators

Please note that this is the README for consumers, if you plan on contributing to this package, please take a look here.

A set of South African specific validators for Angular forms.

Getting Started🏁

If you plan on contributing to the package please read the contributor readme.

  1. Run npm install rh-angular-rsa-form-validators in your Angular project.

  2. Import and use the exposed classes to validate your Angular form controls.

Usage💡

To begin validating your South African specific form fields, start by importing the RsaFormValidators class.

import { RsaFormValidator } from 'rh-angular-rsa-form-validators'

Add the appropriate validator to your form control(s).

// When creating your form
this.form = this.formBuilder.group({
    name: ['', Validators.required],
    mobileNumber: ['', [Validators.required, RsaFormValidator.phoneNumber(false, true)]],
    workNumber: ['']
})

// After the form is already created
this.form.controls['workNumber'].setValidators([RsaFormValidators.phoneNumber(false, true)])

To determine if the form control passed the validation, check the errors object on the form control.

RsaFormValidator error objects on form controls will always be the name of the validator, prefixed with 'rsa' eg; for the rsa phone number validator, the error object is rsaPhoneNumber (rsa + phoneNumber = rsaPhoneNumber)

if (this.form.controls['mobileNumber'].errors.rsaPhoneNumber)
    errorMessage = 'Mobile number must be a valid South African phone number.'

API Reference📖

RsaFormValidator

Contains form control validators used to validate South African specific form fields.

source code

Methods

phoneNumber(allowCountryCode, allowSpaces)

Returns a validator which determines if a form control is a valid South African phone number.

Parameters

Name Type Description Default
allowCountryCode boolean determines if the phone number is allowed to contain the South African country code (+27) true
allowSpaces boolean determines if a phone number is allowed to contain spaces true

Package Sidebar

Install

npm i @runninghill/ng-rsa-form-validators

Weekly Downloads

2

Version

1.2.0

License

MIT

Unpacked Size

16.5 kB

Total Files

16

Last publish

Collaborators

  • arnoventer
  • henkbothma
  • renier_lillie
  • marcelvw123
  • bananman