Skip to content

Commit

Permalink
remove custom validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshataKatwal16 committed Jul 29, 2024
1 parent 5367709 commit d319c98
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
onChange(event);
}

const customValidate = (formData: any, errors: any) => {
if (formData.name && /\d/.test(formData.name)) {
errors.name.addError(t('FORM_ERROR_MESSAGES.NAME_CANNOT_INCLUDE_DIGITS'));
}

if (formData.father_name && /\d/.test(formData.father_name)) {
errors.father_name.addError(t('FORM_ERROR_MESSAGES.NAME_CANNOT_INCLUDE_DIGITS'));
}

const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (formData.email && !emailPattern.test(formData.email)) {
errors.email.addError(t('FORM_ERROR_MESSAGES.INVALID_EMAIL_FORMAT'));
}

return errors;
};


return (
<div>
<FormWithMaterialUI
Expand All @@ -150,7 +134,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
onError={handleError}
transformErrors={transformErrors}
fields={customFields}
customValidate={customValidate} // Add customValidate function here

>
{children}
</FormWithMaterialUI>
Expand Down

0 comments on commit d319c98

Please sign in to comment.