update validation
This commit is contained in:
Generated
+12
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "no-copy-frontend",
|
||||
"version": "0.10.0",
|
||||
"version": "0.15.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "no-copy-frontend",
|
||||
"version": "0.10.0",
|
||||
"version": "0.15.0",
|
||||
"dependencies": {
|
||||
"@react-input/mask": "^2.0.4",
|
||||
"@tailwindcss/postcss": "^4.1.17",
|
||||
@@ -24,6 +24,7 @@
|
||||
"recharts": "^3.5.1",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwindcss": "^4.1.17",
|
||||
"validator": "^13.15.26",
|
||||
"zod": "^4.1.13",
|
||||
"zustand": "^5.0.9"
|
||||
},
|
||||
@@ -7774,6 +7775,15 @@
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/validator": {
|
||||
"version": "13.15.26",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-13.15.26.tgz",
|
||||
"integrity": "sha512-spH26xU080ydGggxRyR1Yhcbgx+j3y5jbNXk/8L+iRvdIEQ4uTRH2Sgf2dokud6Q4oAtsbNvJ1Ft+9xmm6IZcA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/victory-vendor": {
|
||||
"version": "37.3.6",
|
||||
"resolved": "https://registry.npmjs.org/victory-vendor/-/victory-vendor-37.3.6.tgz",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"recharts": "^3.5.1",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwindcss": "^4.1.17",
|
||||
"validator": "^13.15.26",
|
||||
"zod": "^4.1.13",
|
||||
"zustand": "^5.0.9"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import * as z from 'zod';
|
||||
//@ts-ignore
|
||||
import validator from 'validator';
|
||||
|
||||
interface FieldConfig {
|
||||
maxSize?: { value: number; message: string };
|
||||
@@ -15,7 +17,7 @@ interface ValidationConfig {
|
||||
[key: string]: FieldConfig;
|
||||
}
|
||||
|
||||
const EMAIL_REGEX = /^([a-z0-9.\-_]+|[а-яё0-9.\-_]+)@(([a-z0-9.\-]+)\.([a-z]{2,})|([a-z0-9.\-]+)\.([а-яё]{2,})|([а-яё0-9.\-]+)\.([a-z]{2,})|([а-яё0-9.\-]+)\.([а-яё]{2,}))$/i;
|
||||
/* const EMAIL_REGEX = /^([a-z0-9.\-_]+|[а-яё0-9.\-_]+)@(([a-z0-9.\-]+)\.([a-z]{2,})|([a-z0-9.\-]+)\.([а-яё]{2,})|([а-яё0-9.\-]+)\.([a-z]{2,})|([а-яё0-9.\-]+)\.([а-яё]{2,}))$/i; */
|
||||
|
||||
export function createValidationSchema(config: ValidationConfig) {
|
||||
const schema: Record<string, any> = {};
|
||||
@@ -64,11 +66,13 @@ export function createValidationSchema(config: ValidationConfig) {
|
||||
);
|
||||
}
|
||||
|
||||
// Валидация email формата (если включено)
|
||||
if (config.email.emailValidation?.value) {
|
||||
emailSchema = emailSchema.refine(
|
||||
(value) => EMAIL_REGEX.test(value),
|
||||
{ message: config.email.emailValidation.message || 'register-error-email-invalid' }
|
||||
(value) => validator.isEmail(value, {
|
||||
allow_utf8_local_part: true,
|
||||
require_tld: true,
|
||||
}),
|
||||
{ message: config.email.emailValidation.message }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ 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, '');
|
||||
e.target.value = e.target.value.replace(/([^a-zA-Zа-яёА-ЯЁ0-9@.!#$%&'*+/=?^_{|}~\-\s])/g, '');
|
||||
}
|
||||
const validatedField = validateField(fieldName, e.target.value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user