Skip to content

Commit

Permalink
Merge pull request #549 from AVNI-THEEXPLORER/register
Browse files Browse the repository at this point in the history
🔗fix: Update Register.jsx
  • Loading branch information
dhairyagothi authored Jan 26, 2025
2 parents 4cd48e8 + 87eaa4a commit fb7dfd7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion frontend/src/Pages/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,22 @@ const Register = () => {
type="text"
id="username"
value={username}
onChange={(e) => setUserName(e.target.value)}
onChange={(e) => {
const value = e.target.value;
// Validate the input: Only allow alphabetic characters
if (/^[a-zA-Z]*$/.test(value)) {
setUserName(value); // Update state only if valid
setErrors((prevErrors) => {
const { username, ...rest } = prevErrors;
return rest; // Remove username error if input is valid
});
} else {
setErrors((prevErrors) => ({
...prevErrors,
username: "Username can only contain alphabetic characters",
}));
}
}}
placeholder="Enter your username"
className="w-full px-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
required
Expand Down

0 comments on commit fb7dfd7

Please sign in to comment.