Skip to content

Commit

Permalink
check & validate special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Lal committed Apr 7, 2024
1 parent 77036bb commit 224f274
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions client/src/components/modal/brief-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const BriefInfo: React.FC<RegisterDataProps> = ({ registerData, setRegisterData

const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
const specialCharRegex = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/;
if (specialCharRegex.test(value)) {
return toast.warning('Special characters not allowed.');
}

setRegisterData(prevState => ({
...prevState,
[name]: value
Expand Down
6 changes: 3 additions & 3 deletions server/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down

0 comments on commit 224f274

Please sign in to comment.