From 339419fed3e08dddb54e8143fbbacffaffdcad49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=AD=20Siqueira?= Date: Fri, 24 May 2019 10:05:39 -0300 Subject: [PATCH 1/2] Added URL validator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raí Siqueira --- projects/justa/br-validators/README.md | 1 + .../justa/br-validators/src/validators/index.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/projects/justa/br-validators/README.md b/projects/justa/br-validators/README.md index 35dfa35..6167cc7 100644 --- a/projects/justa/br-validators/README.md +++ b/projects/justa/br-validators/README.md @@ -48,6 +48,7 @@ export class AppComponent { - validateCNPJ (format: xx.xxx.xxx/xxxx-xx | xxxxxxxxxxxxxx) - validateCPF (format: xxx.xxx.xxx-xx | xxxxxxxxxxx) - validatePhone (format: (xx)xxxxx-xxxx | (xx)xxxx-xxxx | xxxxxxxxxx) +- validateURL (format: http[s]://lol.com) ## Build (dev only) diff --git a/projects/justa/br-validators/src/validators/index.ts b/projects/justa/br-validators/src/validators/index.ts index 95b0167..d983f5e 100644 --- a/projects/justa/br-validators/src/validators/index.ts +++ b/projects/justa/br-validators/src/validators/index.ts @@ -8,6 +8,10 @@ import * as Moment from "moment"; const moment = Moment; +const urlPattern = new RegExp( + /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/ +); + /** * @description remove all non digits caracters */ @@ -60,9 +64,20 @@ function validatePhone(control: AbstractControl): ValidationErrors | null { : null; } +/** + * @description validateURL for FormBuilder + */ +function validateURL(control: AbstractControl): ValidationErrors | null { + const controlValue = control.value; + return !urlPattern.test(controlValue) + ? { isInvalid: { expected: true, message: "URL Inválida." } } + : null; +} + export const jstValidators = { validateDate, validateCNPJ, validateCPF, - validatePhone + validatePhone, + validateURL }; From 096946ccf3276fd8e112bbc008aec8bc0fe53e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=AD=20Siqueira?= Date: Fri, 24 May 2019 10:06:01 -0300 Subject: [PATCH 2/2] V1.0.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raí Siqueira --- projects/justa/br-validators/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/justa/br-validators/package.json b/projects/justa/br-validators/package.json index 2d8304a..ba110f0 100644 --- a/projects/justa/br-validators/package.json +++ b/projects/justa/br-validators/package.json @@ -1,6 +1,6 @@ { "name": "@justa/ng-validators", - "version": "0.2.0", + "version": "1.0.0", "peerDependencies": { "@angular/common": "^5.0.0 || ^6.0.0 || ^7.0.0", "@angular/core": "^5.0.0 || ^6.0.0 || ^7.0.0",