diff options
author | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2021-10-26 08:57:50 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-26 08:57:50 +0530 |
commit | 2edcf95e6cf390e4511e3bfd61cdab6057cd6adc (patch) | |
tree | b85c62fb608612f23c178c8d19f9598e2b48fe8b /src/helpers/validation-helpers.ts | |
parent | docs: added 'sreelekhaMarasig' as contributor for code [skip ci] (diff) | |
download | ferdium-app-2edcf95e6cf390e4511e3bfd61cdab6057cd6adc.tar.gz ferdium-app-2edcf95e6cf390e4511e3bfd61cdab6057cd6adc.tar.zst ferdium-app-2edcf95e6cf390e4511e3bfd61cdab6057cd6adc.zip |
Diffstat (limited to 'src/helpers/validation-helpers.ts')
-rw-r--r-- | src/helpers/validation-helpers.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/helpers/validation-helpers.ts b/src/helpers/validation-helpers.ts index 23c297443..dfaf199ee 100644 --- a/src/helpers/validation-helpers.ts +++ b/src/helpers/validation-helpers.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { defineMessages } from 'react-intl'; | 1 | import { defineMessages } from 'react-intl'; |
2 | import isEmail from 'validator/lib/isEmail'; | 2 | import isEmail from 'validator/lib/isEmail'; |
3 | import { isValidExternalURL, isValidFileUrl } from './url-helpers'; | ||
3 | 4 | ||
4 | const messages = defineMessages({ | 5 | const messages = defineMessages({ |
5 | required: { | 6 | required: { |
@@ -47,17 +48,17 @@ export function email({ field }) { | |||
47 | 48 | ||
48 | export function url({ field }) { | 49 | export function url({ field }) { |
49 | const value = field.value.trim(); | 50 | const value = field.value.trim(); |
50 | let isValid = false; | 51 | let isValid = true; |
51 | 52 | ||
52 | isValid = | 53 | if (value !== '') { |
53 | value !== '' | 54 | if (value.startsWith('http')) { |
54 | ? Boolean( | 55 | isValid = isValidExternalURL(value); |
55 | // eslint-disable-next-line unicorn/better-regex | 56 | } else if (value.startsWith('file')) { |
56 | /(^|[\s.:;?\-\]<(])(https?:\/\/[-\w;/?:@&=+$|_.!~*|'()[\]%#,☺]+[\w/#](\(\))?)(?=$|[\s',|().:;?\-[\]>)])/i.test( | 57 | isValid = isValidFileUrl(value); |
57 | value, | 58 | } else { |
58 | ), | 59 | isValid = false; |
59 | ) | 60 | } |
60 | : true; | 61 | } |
61 | 62 | ||
62 | return [ | 63 | return [ |
63 | isValid, | 64 | isValid, |