### File

`src/factory/validator-factory.ts`

### Index

###### Methods
Public createEmailValidator Public createMaxLengthValidator Public createMaxValidator Public createMinLengthValidator Public createMinValidator Public createPatternValidator Public createRequiredValidator

### Constructor

`constructor(validation: Validation)`
Defined in src/factory/validator-factory.ts:5
Parameters :
Name | Type | Optional | Description
validation | `Validation` |  |

### Methods

Public createEmailValidator
`createEmailValidator()`
Defined in src/factory/validator-factory.ts:9
Returns : `ValidatorFn`

Public createMaxLengthValidator
`createMaxLengthValidator()`
Defined in src/factory/validator-factory.ts:21
Returns : `ValidatorFn`

Public createMaxValidator
`createMaxValidator()`
Defined in src/factory/validator-factory.ts:13
Returns : `ValidatorFn`

Public createMinLengthValidator
`createMinLengthValidator()`
Defined in src/factory/validator-factory.ts:25
Returns : `ValidatorFn`

Public createMinValidator
`createMinValidator()`
Defined in src/factory/validator-factory.ts:17
Returns : `ValidatorFn`

Public createPatternValidator
`createPatternValidator()`
Defined in src/factory/validator-factory.ts:29
Returns : `ValidatorFn`

Public createRequiredValidator
`createRequiredValidator()`
Defined in src/factory/validator-factory.ts:43
Returns : `ValidatorFn`

    import { ValidatorFn, Validators } from '@angular/forms';

    import { Validation, Email, Max, Min, MaxLength, MinLength, Pattern, Required } from '../validation';

    export class ValidatorFactory {

      public constructor(private validation: Validation) { }

      public createEmailValidator(): ValidatorFn {
        return Validators.email;
      }

      public createMaxValidator(): ValidatorFn {
        return Validators.max((<Max>this.validation).value);
      }

      public createMinValidator(): ValidatorFn {
        return Validators.min((<Min>this.validation).value);
      }

      public createMaxLengthValidator(): ValidatorFn {
        return Validators.maxLength((<MaxLength>this.validation).value);
      }

      public createMinLengthValidator(): ValidatorFn {
        return Validators.minLength((<MinLength>this.validation).value);
      }

      public createPatternValidator(): ValidatorFn {
        const value: string = (<Pattern>this.validation).value;

        if (value.startsWith('/')) {
          const valuePattern: RegExp = /\/(.*)\/([gim]+)?/;
          const pattern: string = value.replace(valuePattern, '$1');
          const flags: string = value.replace(valuePattern, '$2');

          return Validators.pattern(new RegExp(pattern, flags));
        }

        return Validators.pattern(value);
      }

      public createRequiredValidator(): ValidatorFn {
        return !(<Required>this.validation).requiredTrue ? Validators.required : Validators.requiredTrue;
      }
    }

# results matching ""

# No results matching ""