edit validation, add new validation message
This commit is contained in:
@@ -161,6 +161,7 @@ export async function registration(
|
||||
password,
|
||||
confirm_password,
|
||||
agree,
|
||||
companyName
|
||||
});
|
||||
|
||||
if (!validatedFields.success) {
|
||||
|
||||
@@ -23,15 +23,13 @@ export const SignupFormSchema = z
|
||||
fullName: z
|
||||
.string()
|
||||
.min(2, { error: 'register-error-name' })
|
||||
.regex(/^[^0-9]*$/, { message: 'register-error-no-digits' })
|
||||
/* .refine(
|
||||
(value) => !/\p{Emoji}/u.test(value),
|
||||
{ message: 'no-emoji-allowed' }
|
||||
) */
|
||||
.max(100, { error: 'register-error-max-name' })
|
||||
.regex(/^[a-zA-Zа-яА-ЯёЁ\s\-'.]*$/, { message: 'register-error-no-digits' })
|
||||
.trim(),
|
||||
email: z
|
||||
.string()
|
||||
.trim()
|
||||
.max(254, { error: 'register-error-max-email' })
|
||||
.refine(
|
||||
(value) => value === value.toLowerCase(),
|
||||
{ message: 'email-no-uppercase' }
|
||||
@@ -48,16 +46,45 @@ export const SignupFormSchema = z
|
||||
.min(8, { error: 'register-error-password-symbols' })
|
||||
.regex(/[a-zA-Zа-яёА-ЯЁ]/, { error: 'register-error-password-one-letter' })
|
||||
.regex(/[0-9]/, { error: 'register-error-password-one-digit' })
|
||||
/* .refine(
|
||||
(value) => !/\p{Emoji}/u.test(value),
|
||||
{ message: 'no-emoji-allowed' }
|
||||
) */
|
||||
.max(124, { error: 'register-error-max-passowrd' })
|
||||
.trim(),
|
||||
confirm_password: z
|
||||
.string(),
|
||||
agree: z
|
||||
.string()
|
||||
.min(2, { error: 'register-error-agree' })
|
||||
.min(2, { error: 'register-error-agree' }),
|
||||
companyName: z
|
||||
.string()
|
||||
.optional()
|
||||
.nullable()
|
||||
.refine(
|
||||
(value) => {
|
||||
if (!value || value.trim().length === 0) return true;
|
||||
return value.trim().length >= 2;
|
||||
},
|
||||
{ message: 'register-error-company-name' }
|
||||
)
|
||||
.refine(
|
||||
(value) => {
|
||||
const trimmed = value ? value.trim() : '';
|
||||
return trimmed.length === 0 || trimmed.length <= 200;
|
||||
},
|
||||
{
|
||||
message: 'register-error-company-name-max',
|
||||
path: ['companyName']
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(value) => {
|
||||
if (!value || value.trim().length === 0) return true;
|
||||
const regex = /^[a-zA-Zа-яА-ЯёЁ0-9\s\-&.,'"()]+$/;
|
||||
return regex.test(value);
|
||||
},
|
||||
{
|
||||
message: 'companyName-invalid-chars',
|
||||
path: ['companyName']
|
||||
}
|
||||
),
|
||||
})
|
||||
.refine((data) => data.password === data.confirm_password, {
|
||||
message: 'repeat-password',
|
||||
|
||||
@@ -67,6 +67,7 @@ export default function RegisterForm() {
|
||||
case 'fullName':
|
||||
case 'phone':
|
||||
case 'password':
|
||||
case 'companyName':
|
||||
case 'agree':
|
||||
const schema = SignupFormSchema.shape[fieldName];
|
||||
if (fieldName === 'phone') {
|
||||
@@ -81,6 +82,9 @@ export default function RegisterForm() {
|
||||
|
||||
function onChangeHandler(e: ChangeEvent<HTMLInputElement>): void {
|
||||
const fieldName = e.target.name;
|
||||
if (fieldName !== 'phone') {
|
||||
e.target.value = e.target.value.replace(/[^a-zA-Zа-яёА-ЯЁ0-9@#$%^&*_\-\.?!'"\s]/g, '');
|
||||
}
|
||||
const validatedField = validateField(fieldName, e.target.value);
|
||||
|
||||
if (validatedField.success) {
|
||||
@@ -190,7 +194,22 @@ export default function RegisterForm() {
|
||||
className={`${styles['form-input']}`}
|
||||
placeholder={t('company-placeholder')}
|
||||
defaultValue={formState?.previousState?.companyName ? formState?.previousState?.companyName : ''}
|
||||
onChange={onChangeHandler}
|
||||
/>
|
||||
{formState?.error?.companyName && (
|
||||
<p className="text-sm text-red-500">
|
||||
{
|
||||
formState?.error?.companyName.split('&').map((e, index) => {
|
||||
return (
|
||||
<span key={index}>
|
||||
{t(e)}
|
||||
<br />
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className={`${styles['form-group']}`}>
|
||||
|
||||
Reference in New Issue
Block a user