File

projects/common/lib/components/postal-code/validate-bc-postal.directive.ts

Implements

Validator

Metadata

Providers { provide: NG_VALIDATORS, useExisting: ValidateBcPostalDirective, multi: true }
Selector [commonValidateBcPostal]

Index

Methods

Methods

validate
validate(control: AbstractControl)
Parameters :
Name Type Optional
control AbstractControl No
Returns : literal type | null
import { Directive } from '@angular/core';
import { NG_VALIDATORS, Validator, AbstractControl, ValidatorFn, ValidationErrors } from '@angular/forms';


// TODO: determine whether this is used or not.  If not use, maybe it can be removed
//  @deprecated - logic added to validate-postalcode directive
export const commonValidateBcPostal: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
  /**
  * Valid characters for BC postal code
  */
 const criteria: RegExp = RegExp('^[Vv]\\d[ABCEGHJ-NPRSTV-Zabceghj-nprstv-z][ ]?\\d[ABCEGHJ-NPRSTV-Zabceghj-nprstv-z]\\d$');

  if ( control.value ) {
    return criteria.test( control.value ) ? null : { 'invalidBCPostal': true };
  }
  return null;
};

@Directive({
  selector: '[commonValidateBcPostal]',
  providers: [
    {provide: NG_VALIDATORS, useExisting: ValidateBcPostalDirective, multi: true}
  ]
})
export class ValidateBcPostalDirective implements Validator {

  validate( control: AbstractControl ): {[key: string]: any} | null {
    return commonValidateBcPostal( control );
  }
}

result-matching ""

    No results matching ""