From 74201e8bb0b626f5e2b638532136ce879c0756a4 Mon Sep 17 00:00:00 2001 From: zatkiller Date: Tue, 7 Dec 2021 22:13:43 +0800 Subject: [PATCH] feat: enable M series FIN validation --- src/app/utils/field-validation/validators/nricValidator.ts | 7 +++++-- .../base/directives/validate-nric.client.directive.js | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/utils/field-validation/validators/nricValidator.ts b/src/app/utils/field-validation/validators/nricValidator.ts index 7747c2b1e1..9050cdf652 100644 --- a/src/app/utils/field-validation/validators/nricValidator.ts +++ b/src/app/utils/field-validation/validators/nricValidator.ts @@ -1,7 +1,10 @@ import { chain, left, right } from 'fp-ts/lib/Either' import { flow } from 'fp-ts/lib/function' -import { isNricValid } from '../../../../../shared/utils/nric-validation' +import { + isMFinSeriesValid, + isNricValid, +} from '../../../../../shared/utils/nric-validation' import { ResponseValidator } from '../../../../types/field/utils/validation' import { ProcessedSingleAnswerResponse } from '../../../modules/submission/submission.types' @@ -15,7 +18,7 @@ type NricValidatorConstructor = () => NricValidator * format is correct. */ const nricValidator: NricValidator = (response) => { - return isNricValid(response.answer) + return isNricValid(response.answer) || isMFinSeriesValid(response.answer) ? right(response) : left(`NricValidator:\tanswer is not a valid NRIC`) } diff --git a/src/public/modules/forms/base/directives/validate-nric.client.directive.js b/src/public/modules/forms/base/directives/validate-nric.client.directive.js index 165c98029a..224f0689a5 100644 --- a/src/public/modules/forms/base/directives/validate-nric.client.directive.js +++ b/src/public/modules/forms/base/directives/validate-nric.client.directive.js @@ -2,6 +2,7 @@ const { isNricValid, + isMFinSeriesValid, } = require('../../../../../../shared/utils/nric-validation') angular.module('forms').directive('validateNric', validateNric) @@ -12,7 +13,9 @@ function validateNric() { require: 'ngModel', link: function (_scope, _elem, _attrs, ctrl) { ctrl.$validators.nricValidator = function (modelValue) { - return ctrl.$isEmpty(modelValue) ? true : isNricValid(modelValue) + return ctrl.$isEmpty(modelValue) + ? true + : isNricValid(modelValue) || isMFinSeriesValid(modelValue) } }, }