Skip to content

Commit

Permalink
Adding input validations in all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
harshbhar0629 committed Oct 29, 2024
1 parent 3532bd3 commit ac40f39
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
18 changes: 18 additions & 0 deletions QuizQuestFrontend/src/components/contact/ContactUsForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ const ContactUsForm = ({ border }) => {

const submitContactForm = async (data) => {
console.log("Form Data - ", data);
const emailRegex = /^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$/;
console.log(data.email)
if (!data.firstname || !data.email) {
toast.error("Please fill in all fields");
return;
}

if (!emailRegex.test(data.email)) {
toast.error("Please enter valid email");
return;
}

if (data.message.length < 4) {
toast.error("Please enter valid message")
return;
}


const toastId = toast.loading("Loading...");
setTimeout(() => {
toast.dismiss(toastId);
Expand Down
25 changes: 24 additions & 1 deletion QuizQuestFrontend/src/pages/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,30 @@ function Signup() {
if (formData.password !== formData.cpassword) {
toast.error("Incorrect Password!");
return;
}
}

const emailRegex = /^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$/;
// Password validation regex (at least 8 characters, one uppercase, one lowercase, one digit, one special character)
const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;


if (!formData.name || !formData.email || !formData.password) {
toast.error("Please fill in all fields");
return;
}

if (!emailRegex.test(formData.email)) {
toast.error("Please enter valid email");
return;
}

if (!passwordRegex.test(formData.password)) {
toast.error(
"Password having at least 8 characters, one uppercase, one lowercase, one digit, one special character"
);
return;
}

toast.success("Signup successfully");
navigate("/");
console.log(formData);
Expand Down

0 comments on commit ac40f39

Please sign in to comment.