From 224f274f6887cc35a115cf564efd7207ee07e553 Mon Sep 17 00:00:00 2001 From: Shubham-Lal Date: Sun, 7 Apr 2024 22:32:47 +0530 Subject: [PATCH] check & validate special characters --- client/src/components/modal/brief-info.tsx | 5 +++++ server/routes/auth.js | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/components/modal/brief-info.tsx b/client/src/components/modal/brief-info.tsx index 78c394d..718a2cd 100644 --- a/client/src/components/modal/brief-info.tsx +++ b/client/src/components/modal/brief-info.tsx @@ -26,6 +26,11 @@ const BriefInfo: React.FC = ({ registerData, setRegisterData const handleInputChange = useCallback((e: React.ChangeEvent) => { const { name, value } = e.target; + const specialCharRegex = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/; + if (specialCharRegex.test(value)) { + return toast.warning('Special characters not allowed.'); + } + setRegisterData(prevState => ({ ...prevState, [name]: value diff --git a/server/routes/auth.js b/server/routes/auth.js index 9852693..fba5701 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -9,9 +9,9 @@ module.exports = async function (fastify, opts) { email: { type: 'string', format: 'email', minLength: 1 }, password: { type: 'string', minLength: 6 }, avatar: { type: 'string', nullable: true }, - username: { type: 'string', minLength: 1 }, - first_name: { type: 'string', minLength: 1 }, - last_name: { type: 'string', minLength: 1 } + username: { type: 'string', minLength: 1, pattern: '^[a-zA-Z0-9]+$' }, + first_name: { type: 'string', minLength: 1, pattern: '^[a-zA-Z0-9]+$' }, + last_name: { type: 'string', minLength: 1, pattern: '^[a-zA-Z0-9]+$' } }, required: ['email', 'password', 'username', 'first_name', 'last_name'] }