emoji checker on text and multiline
This commit is contained in:
@@ -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 (
|
||||
<>
|
||||
{" "}
|
||||
|
||||
Reference in New Issue
Block a user