From f37290f489cab19942182faca0e65e2e1c8d000a Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Mon, 2 Dec 2024 15:56:18 +0000 Subject: [PATCH] emoji checker on text and multiline --- .env.local | 5 +- components/elements/index.js | 60 +++++++++++++++++++++-- components/myportal/topthree.js | 73 ++++++++++++++++++++-------- components/newappeal/aboutyou.js | 74 +++++++++++++++++++++++++++-- data/formsxml/planningappeals78.xml | 2 +- locales/cy/newappeal.json | 3 +- locales/en/newappeal.json | 3 +- 7 files changed, 190 insertions(+), 30 deletions(-) diff --git a/.env.local b/.env.local index 8e65b367..465283be 100644 --- a/.env.local +++ b/.env.local @@ -141,4 +141,7 @@ APPLICATIONINSIGHTS_CONNECTIONSTRING = InstrumentationKey=7a06e24a-793c-47bc-898 NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=7370f0f9-834d-4c7a-b3c4-9951fcad5ad2;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=04362cb7-6dfc-469e-8274-12243e8be851 // Prod Connection string -//NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=61f358c2-8075-4164-b897-17bc6dd31fee;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=0c297349-396b-4dc6-8b56-85f5c680adc6 \ No newline at end of file +//NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=61f358c2-8075-4164-b897-17bc6dd31fee;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=0c297349-396b-4dc6-8b56-85f5c680adc6 + + +HIDEERRORLOGS = false \ No newline at end of file diff --git a/components/elements/index.js b/components/elements/index.js index 1c1a74b2..908de2fd 100644 --- a/components/elements/index.js +++ b/components/elements/index.js @@ -94,8 +94,28 @@ export function Textfield(props) { maxFieldLength, hint, } = props; - const required = (value) => - value ? undefined : t("newappeal:is-required-label"); + // const required = (value) => + // value ? undefined : t("newappeal:is-required-label"); + + const required = (value) => { + let errors; + + // Check for the required field + if (!value) { + errors = t("newappeal:is-required-label"); + } else { + // Check for emojis using a regular expression + const emojiRegex = + /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu; + + if (emojiRegex.test(value)) { + errors = "Emojis are not allowed"; + } + } + + return errors; + }; + const postcode = (value) => value && !/^([A-Z][A-HJ-Y]?[0-9][A-Z0-9]? ?[0-9][A-Z]{2}|GIR ?0A{2})$/i.test( @@ -271,7 +291,25 @@ export function MultiLinefield(props) { maxFieldLength, hint, } = props; - const required = (value) => (value ? undefined : "Is required"); + + const required = (value) => { + let errors; + + // Check for the required field + if (!value) { + errors = "This field is required"; + } else { + // Check for emojis using a regular expression + const emojiRegex = + /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu; + + if (emojiRegex.test(value)) { + errors = "Emojis are not allowed"; + } + } + + return errors; + }; var showIfHasParentShowValue = parentField != false && @@ -2004,6 +2042,20 @@ const RenderSubFields = ({ fields }) => { let subTitle = fields.name.split("pinswg_")[1]; + const checkValue = (value) => { + let errors; + + // Check for emojis using a regular expression + const emojiRegex = + /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu; + + if (emojiRegex.test(value)) { + errors = "Emojis are not allowed"; + } + + return errors; + }; + return (