Skip to content
This repository has been archived by the owner on Nov 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #31 from matheusnascgomes/feature/new-validator
Browse files Browse the repository at this point in the history
New validators for key text
  • Loading branch information
Raí Siqueira authored Jun 20, 2019
2 parents c8b5e5c + 11796d1 commit 5b18650
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion projects/justa/br-validators/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 18 additions & 1 deletion projects/justa/br-validators/src/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit 5b18650

Please sign in to comment.