১৯-২ : regex ব্যবহার করে পাসওয়ার্ড ভ্যালিডেশন

এই মডিউলে আমরা রেজিস্ট্রেশন ফর্মের ভ্যালিডেশন করব।

এর জন্য auth.js ফাইলের handleRegistration( ) ফাঙ্গশন নিচের মত করে লিখে ফেলি-

Code:: 19.2.1 app.js

...
...
...
    
  const handleRegistration = (event) => {
    event.preventDefault();
    const username = getValue("username");
    const first_name = getValue("first_name");
    const last_name = getValue("last_name");
    const email = getValue("email");
    const password = getValue("password");
    const confirm_password = getValue("confirm_password");
    const info = {
      username,
      first_name,
      last_name,
      email,
      password,
      confirm_password,
    };
  
    if (password === confirm_password) {
      document.getElementById("error").innerText = "";
      if (
        /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/.test(
          password
        )
      ) {
        console.log(info);
  
        fetch("https://testing-8az5.onrender.com/patient/register/", {
          method: "POST",
          headers: { "content-type": "application/json" },
          body: JSON.stringify(info),
        })
          .then((res) => res.json())
          .then((data) => console.log(data));
      } else {
        document.getElementById("error").innerText =
          "pass must contain eight characters, at least one letter, one number and one special character:";
      }
    } else {
      document.getElementById("error").innerText =
        "password and confirm password do not match";
      alert("password and confirm password do not match");
    }
  };

...
...
...

এখন , password ও confirm_password ফিল্ডে সেইম ইনপুট না দিলে ইরোর মেসেজ পাওয়া যাচ্ছে-

.

Last updated