[Angular] 身分證驗證器(directive Validator)
身分證的產生和驗證是很常見的表單需求 idno-valiator.directive.ts import { AbstractControl , ValidatorFn } from ' @angular/forms ' ; export function IdnoValiator () : ValidatorFn { return ( control : AbstractControl ) : { [ key : string ] : any } | null => { if ( ! control . value ) { return null ; } const valid = checkID ( control . value ) ; return valid ? null : { idnoCheck : true }; }; } function checkID ( id ) { // 建立字母分數陣列(A~Z) const city = new Array ( 1 , ...