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,OAAO,kBAAA,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,CAAC;QANe,iCAAe,kBAM9B,CAAA;QAEY,+BAAa,GAAW,iDAAiD,CAAC;QAC1E,2BAAS,GAAW,+DAA+D,CAAC;QACpF,0BAAQ,GAAW,mDAAmD,CAAC;QACvE,+BAAa,GAAW,WAAW,CAAC;QACpC,kCAAgB,GAAW,YAAY,CAAC;IACzD,CAAC,EA3GgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QA2GjC","file":"validationService.js","sourcesContent":["import 'knockout.validation';\r\nimport * as ko from \"knockout\";\r\n\r\nexport namespace ValidationService {\r\n // Purpose : There are occasions where we'll change the context of a page and it'll immediately validate\r\n // the form. Whilst this is a good thing, it's also not great when it immediately pops up the\r\n // validation messages as soon as you open modal, panel or whatever is being displayed. This will\r\n // remove that issue in it's entirety so call it wisely.\r\n export function HideAllMessages(validationFields: KnockoutObservable[]): void {\n const validationMessages =\n ko.validation.group(validationFields, { deep: true });\n\n validationMessages.showAllMessages(false);\r\n }\r\n\r\n // Purpose : There are occasions where we'll change the context of a value and it'll immediately validate\r\n // group form properties (i.e. where one form properties depends on another to function). Whilst\r\n // this is a good thing, it's also not great when it immediately pops up the validation messages\r\n // as the linked property is displayed. This will remove that issue in it's entirety so call it\r\n // wisely.\r\n export function HideValidationMessage(value: KnockoutObservable): void {\r\n if (value.isModified) {\r\n value.isModified(false);\r\n }\r\n }\r\n\r\n export function AddValidationRule(field: KnockoutObservable, validationFields: KnockoutObservable[], rule: any): void {\n field.extend(rule);\n validationFields.push(field);\n }\r\n\r\n // Purpose : This is intended to resolve an ordering problem that can arise when you try and initialise a binding that relies on the validation\r\n // properties of an observable before any validation is applied (so things like the 'isValid' function don't exist yet).\r\n // This can happen in cases where a child UI component handles the validation rules, but it hasn't added them\r\n // at the time of binding the parent component.\r\n export function SetObservableValidatable(field: KnockoutObservable, validationFields?: KnockoutObservable[]): void {\r\n field.extend({ validatable: true });\r\n validationFields?.push(field);\r\n }\r\n\r\n export function RemoveValidationRule(field: KnockoutObservable, validationFields: KnockoutObservable[]): void {\n var index = validationFields.indexOf(field);\r\n\r\n if (index >= 0) {\r\n validationFields.splice(index, 1);\r\n }\r\n }\r\n\r\n // Purpose : Checks that the field(s) are valid with forced mutation of the property(s).\r\n // Usage : Use this on functionality which needs to check that the property is valid and to have any invalid\r\n // properties display the appropriate validation error.\r\n // Example : This is a perfect candidate for methods which are about to submit a request to the server.\r\n // e.g. Pressing the submit button on a form and the action it calls validates the form properties.\r\n export function IsValid(validationFields: KnockoutObservable[]): boolean {\r\n let allValid = true;\r\n\r\n ko.utils.arrayForEach(validationFields, (field: KnockoutObservable) => {\r\n if (field.valueHasMutated !== undefined) {\r\n field.valueHasMutated();\r\n }\r\n\r\n if (!field.isValid()) {\r\n allValid = false;\r\n }\r\n });\r\n\r\n return allValid;\r\n }\r\n\r\n // Purpose : Checks that the field(s) are valid with no forced mutation of the property(s).\r\n // Usage : Use this on functionality which only needs to check that the property is valid without having all\r\n // validation messages being rendered.\r\n // Example : This is a perfect candidate for computed methods which only need to validate whether all the fields\r\n // are valid so that a button is enabled when true.\r\n export function AreFieldsValid(validationFields: KnockoutObservable[]): boolean {\r\n let allValid = true;\r\n\r\n ko.utils.arrayForEach(validationFields, (field: KnockoutObservable) => {\r\n if (!field.isValid()) {\r\n allValid = false;\r\n }\r\n });\r\n\r\n return allValid;\r\n }\n\n export const EmailRegex: RegExp = /^([a-zA-Z0-9_.+-])+\\@(([a-zA-Z0-9-])+\\.)+([a-zA-Z0-9]{2,4})+$/;\r\n export function IsValidEmail(email: string): boolean {\r\n // Treat empty emails as valid; if the email is mandatory there should be a required rule rather than relying on this\r\n if (email === undefined || email === null || email.length === 0) {\r\n return true;\r\n }\r\n\r\n return EmailRegex.test(email);\r\n }\r\n\r\n export const PostCodeRegex: RegExp = /([A-Za-z]{1,2}[0-9Rr][0-9A-Za-z]?)\\s*([0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2})/;\r\n export function IsValidPostCode(postcode: string): boolean {\r\n if (postcode === undefined || postcode === null || postcode.length === 0) {\r\n return true;\r\n }\r\n\r\n return PostCodeRegex.test(postcode);\r\n }\r\n\r\n export const SortCodeRegex: RegExp = /^(?!(?:0{6}|00-00-00))(?:\\d{6}|\\d\\d-\\d\\d-\\d\\d)$/;\r\n export const IBANRegex: RegExp = /[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}/;\r\n export const BICRegex: RegExp = /^[a-z]{6}[2-9a-z][0-9a-np-z]([a-z0-9]{3}|x{3})?$/i;\r\n export const BankCodeRegex: RegExp = /^(\\d{6})$/;\r\n export const TransitCodeRegex: RegExp = /^(0\\d{8})$/;\n}"]}