diff --git a/projects/justa/br-validators/package.json b/projects/justa/br-validators/package.json index ba110f0..adff5fd 100644 --- a/projects/justa/br-validators/package.json +++ b/projects/justa/br-validators/package.json @@ -1,6 +1,6 @@ { "name": "@justa/ng-validators", - "version": "1.0.0", + "version": "1.1.0", "peerDependencies": { "@angular/common": "^5.0.0 || ^6.0.0 || ^7.0.0", "@angular/core": "^5.0.0 || ^6.0.0 || ^7.0.0", diff --git a/projects/justa/br-validators/src/validators/index.ts b/projects/justa/br-validators/src/validators/index.ts index d983f5e..21e0ac4 100644 --- a/projects/justa/br-validators/src/validators/index.ts +++ b/projects/justa/br-validators/src/validators/index.ts @@ -74,10 +74,27 @@ function validateURL(control: AbstractControl): ValidationErrors | null { : null; } +/** + * @description Provide a validator for key text that do not accept special characters or spaces + */ +function validateTextKey(control: AbstractControl): ValidationErrors | null { + const controlValue = control.value; + const pattern = /([\u00C0-\u00FF ])/g; + return controlValue.match(pattern) + ? { + isInvalid: { + expected: true, + message: "Não é permitido caracteres especiais ou espaços neste campo" + } + } + : null; +} + export const jstValidators = { validateDate, validateCNPJ, validateCPF, validatePhone, - validateURL + validateURL, + validateTextKey };