From 19069da84e3346639e1cd53b460d9fc8e5be72bd Mon Sep 17 00:00:00 2001 From: GermaVinsmoke Date: Wed, 15 Mar 2023 21:07:51 +0530 Subject: [PATCH] search - input field validation Signed-off-by: GermaVinsmoke --- components/search/FilterSidebar.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/components/search/FilterSidebar.js b/components/search/FilterSidebar.js index 2da2986ff..00cdc0c4c 100644 --- a/components/search/FilterSidebar.js +++ b/components/search/FilterSidebar.js @@ -114,7 +114,7 @@ const tomorrowUTC = dayjs.utc().add(1, 'day').format('YYYY-MM-DD') const asnRegEx = /^(AS)?([1-9][0-9]*)$/ const domainRegEx = /(^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,}(:[0-9]{1,5})?$)|(^(([0-9]{1,3})\.){3}([0-9]{1,3}))/ -const inputRegEx = /(^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,}\.[a-zA-Z0-9()]{2,}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$)|(^(([0-9]{1,3})\.){3}([0-9]{1,3}))/ +const inputRegEx = /(^https?:\/\/(?:www\.)?[-a-z0-9@:%._\+~#=]{1,}\.[a-z0-9()]{2,}\b(?:[-a-z0-9()@:%_\+.~#?&\/=]*)$)|(^(([0-9]{1,3})\.){3}([0-9]{1,3}))/ export const queryToFilterMap = { domain: [ 'domainFilter', ''], @@ -298,7 +298,7 @@ const FilterSidebar = ({ { - showDatePicker && + showDatePicker && )} rules={{ - pattern: { - value: inputRegEx, - message: intl.formatMessage({id: 'Search.Sidebar.Input.Error'}) - } + validate: (value = '') => + (String(value).length === 0 || inputRegEx.test(value)) + || intl.formatMessage({id: 'Search.Sidebar.Input.Error'}) }} />