emoji checker on text and multiline

This commit is contained in:
2024-12-02 15:56:18 +00:00
parent 5060932bd7
commit f37290f489
7 changed files with 190 additions and 30 deletions
+57 -3
View File
@@ -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 (
<ul>
<div>
@@ -2019,6 +2071,7 @@ const RenderSubFields = ({ fields }) => {
name={`${member}.${fields.name}`}
type="text"
component={RenderTextfield}
validate={[checkValue]}
label={
subTitle == "owners"
? "Owners name"
@@ -2085,6 +2138,7 @@ export const FieldArrayForm = (props) => {
parentFieldShowOnValue;
const { handleSubmit, pristine, reset, submitting } = props;
return (
<>
{" "}
+54 -19
View File
@@ -65,6 +65,45 @@ const TopThree = (props) => {
return dateB - dateA;
});
// check start
function sortByISODate(arr, dateKey) {
return arr.sort((a, b) => new Date(b[dateKey]) - new Date(a[dateKey]));
}
function sortByField(arr, field, ascending = true) {
return arr.sort((a, b) => {
if (a[field] < b[field]) return ascending ? -1 : 1;
if (a[field] > b[field]) return ascending ? 1 : -1;
return 0; // Equal
});
}
//let showTopThreeArr = showTopThree.value;
let showTopThreeArrDets = showDetails;
showTopThreeArr = sortByField(showTopThreeArr, "ticketnumber");
//console.log("showTopThreeArr:", showTopThreeArr);
showTopThreeArrDets = sortByField(showTopThreeArrDets, "pinswg_name");
//console.log("showTopThreeArrDets:", showTopThreeArrDets);
showTopThreeArrDets = showTopThreeArrDets.flatMap((item) => item.value);
let mergedArray = showTopThreeArr.map((item1) => {
let item2 = showTopThreeArrDets.find(
(item) => item.pinswg_name === item1.ticketnumber
);
return { ...item1, ...item2 };
});
console.log(mergedArray);
showTopThreeArr = mergedArray;
showTopThreeArr = sortByISODate(showTopThreeArr, "createdon");
// check end
const raisedDate = (datePart) => {
var dateObj = new Date(datePart);
return dateObj.toLocaleString();
@@ -130,7 +169,7 @@ const TopThree = (props) => {
}
};
let topThreeOnlyArr = showTopThreeArr.slice(0, 3);
let topThreeOnlyArr = showTopThreeArr; //.slice(0, 3);
Object.keys(topThreeOnlyArr).map((key, index) => {
topthreeRow.push(
<div className="cardModuleItem" key={index}>
@@ -249,34 +288,28 @@ const TopThree = (props) => {
{/* {topThreeType != "awaitingSubmission" ? ( */}
<div className="carModuleAddress">
<b>{t("myportal:case-address")}:</b>{" "}
{_.isEmpty(showDetails)
{_.isEmpty(showTopThreeArr[key])
? t("myportal:case-address-not-entered")
: _.isEmpty(showDetails[index])
: _.isEmpty(showTopThreeArr[key])
? t("myportal:case-address-not-entered")
: _.isEmpty(showDetails[index].value[0])
: _.isEmpty(showTopThreeArr[key])
? t("myportal:case-address-not-entered")
: _.isEmpty(
showDetails[index].value[0]
.pinswg_siteaddressline1
showTopThreeArr[key].pinswg_siteaddressline1
)
? t("myportal:case-address-not-entered")
: showDetails[index].value[0]
.pinswg_siteaddressline1 +
: showTopThreeArr[key].pinswg_siteaddressline1 +
(!_.isEmpty(
showDetails[index].value[0]
.pinswg_siteaddressline2
showTopThreeArr[key].pinswg_siteaddressline2
)
? ", " +
showDetails[index].value[0]
.pinswg_siteaddressline2
showTopThreeArr[key].pinswg_siteaddressline2
: "") +
(!_.isEmpty(
showDetails[index].value[0]
.pinswg_siteaddresstown
showTopThreeArr[key].pinswg_siteaddresstown
)
? ", " +
showDetails[index].value[0]
.pinswg_siteaddresstown
showTopThreeArr[key].pinswg_siteaddresstown
: "")}
</div>
{showTopThreeArr[key].pinswg_appellantagent != null && (
@@ -285,12 +318,14 @@ const TopThree = (props) => {
846040000 && (
<b>{t("myportal:raised-by-label")}: </b>
)}
{showTopThreeArr[key].pinswg_appellantagent !=
846040000 &&
(showTopThreeArr[key].pinswg_agentcompanyname !=
null &&
showTopThreeArr[key]
.pinswg_agentcompanyname + ", ") +
null
? showTopThreeArr[key]
.pinswg_agentcompanyname + ", "
: "") +
showTopThreeArr[key].pinswg_agentfirstname +
" " +
showTopThreeArr[key].pinswg_agentlastname}
+70 -4
View File
@@ -178,7 +178,22 @@ const RenderRadio = ({
...custom
}) => {
let { t } = useTranslation();
const required = (value) => (value ? undefined : "Required");
const required = (value) => {
// Check for the required field
if (!value) {
errors = "This field is required";
}
// 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 (
<>
<div
@@ -301,7 +316,24 @@ function Radiofield(props) {
} = props;
const router = useRouter();
const required = (value) => (value ? undefined : "Required");
const required = (value) => {
let errors = {};
// Check for the required field
if (!value) {
errors = "This field is required";
}
// 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;
};
//console.log(props.options);
const fieldOptions = props.options
@@ -385,7 +417,24 @@ const RenderCheckBox = ({
...custom
}) => {
let { t } = useTranslation();
const required = (value) => (value ? undefined : "Required");
const required = (value) => {
let errors = {};
// Check for the required field
if (!value) {
errors = "This field is required";
}
// 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 (
<>
@@ -455,7 +504,24 @@ let AboutYou = (props) => {
const contactPref =
router.locale == "cy" ? ["Ebost", "Post"] : ["Email", "Post"];
const required = (value) => (value ? undefined : "Is required");
const required = (value) => {
let errors = {};
// Check for the required field
if (!value) {
errors = "This field is required";
}
// 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 emailRegex =
/(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/gi;