From 500b8a5cd4c87f26e2a5b5354604ad1c32714415 Mon Sep 17 00:00:00 2001 From: James Croft Date: Tue, 18 Jan 2022 17:03:12 +0000 Subject: [PATCH] Added ContainsValidator and validator map --- .../src/validators/ContainsValidator.ts | 22 +++++++++++++++++++ .../src/validators/IValidatorMap.ts | 5 +++++ MADE.Data.Validation/src/validators/index.ts | 4 +++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 MADE.Data.Validation/src/validators/ContainsValidator.ts create mode 100644 MADE.Data.Validation/src/validators/IValidatorMap.ts diff --git a/MADE.Data.Validation/src/validators/ContainsValidator.ts b/MADE.Data.Validation/src/validators/ContainsValidator.ts new file mode 100644 index 0000000..8331d51 --- /dev/null +++ b/MADE.Data.Validation/src/validators/ContainsValidator.ts @@ -0,0 +1,22 @@ +import { IValidator } from "./IValidator"; + +export class ContainsValidator implements IValidator { + key: string; + isInvalid: boolean; + isDirty: boolean; + feedbackMessage: string; + options: any[]; + + constructor(options: any[]) { + this.key = "BetweenValidator"; + this.isInvalid = false; + this.isDirty = false; + this.feedbackMessage = `The value is not a valid option.`; + this.options = options; + } + + validate(value: any): void { + this.isInvalid = this.options.indexOf(value) === -1; + this.isDirty = true; + } +} \ No newline at end of file diff --git a/MADE.Data.Validation/src/validators/IValidatorMap.ts b/MADE.Data.Validation/src/validators/IValidatorMap.ts new file mode 100644 index 0000000..75279ca --- /dev/null +++ b/MADE.Data.Validation/src/validators/IValidatorMap.ts @@ -0,0 +1,5 @@ +import { ValidatorArray } from "./ValidatorArray"; + +export interface IValidatorMap { + [key: string]: ValidatorArray; +} \ No newline at end of file diff --git a/MADE.Data.Validation/src/validators/index.ts b/MADE.Data.Validation/src/validators/index.ts index c721fe9..eb1e3c7 100644 --- a/MADE.Data.Validation/src/validators/index.ts +++ b/MADE.Data.Validation/src/validators/index.ts @@ -4,6 +4,7 @@ export * from './RegexValidator'; export * from './AlphaNumericValidator'; export * from './AlphaValidator'; export * from './BetweenValidator'; +export * from './ContainsValidator'; export * from './EmailValidator'; export * from './IpAddressValidator'; export * from './MaxLengthValidator'; @@ -11,4 +12,5 @@ export * from './MaxValueValidator'; export * from './MinLengthValidator'; export * from './MinValueValidator'; export * from './RequiredValidator'; -export * from './ValidatorArray'; \ No newline at end of file +export * from './ValidatorArray'; +export * from './IValidatorMap'; \ No newline at end of file