Guest Mode:

BCA Student Stories & UpdatesLive

You
Your StorySign in & share
Er. Manoj Kumar
D5
Er. ManojActive nowPages
Day 36Advanced JavaScript & Browser APIs2 Hours Practical
Push to GitHub to Complete

Client-Side Form Validation & Real-Time Regex Diagnostics

Form validation protects user experience by identifying input errors before data reaches the server or storage. Real-time validation provides immediate inline feedback, guiding students to enter correctly formatted emails, phone numbers, and strong passwords effortlessly.

Interactive Learning Roadmap

Day 36 Step-by-Step Practical Flow

🎯1. What You Will Learn Today

✔Implement real-time form validation using input and blur events.
✔Construct Regular Expressions (RegEx) to validate Email, 10-digit Phone numbers, and Enrollment numbers.
✔Build dynamic password strength meters checking length, numbers, and special characters.
✔Manage accessible visual validation states using CSS classes (is-valid, is-invalid) and error hint spans.
✔Prevent invalid form submissions and provide instant constructive feedback.
Day 36 MasterclassAdvanced JavaScript & Browser APIs

Client-Side Form Validation & Real-Time Regex Diagnostics — Comprehensive Practical Guide

Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.

Real-World Purpose Aur Zaroorat

Form validation protects user experience by identifying input errors before data reaches the server or storage. Real-time validation provides immediate inline feedback, guiding students to enter correctly formatted emails, phone numbers, and strong passwords effortlessly.

input vs change vs blur: input fires on every keystroke; blur fires when the user leaves the field; submit validates all fields.
RegEx Testing: Use regex.test(value) to return a boolean true or false.
Accessible Hints: Pair input fields with descriptive <span class="error-msg"> elements that explain exact requirements.
Prevent Submission: Only proceed with form processing if all field validators return true; otherwise call e.preventDefault().
Visual Clarity: Use Emerald Green borders for valid inputs and Crimson Red for errors.
Dimaag Mein Bithane Ka Model

"Think of real-time form validation like a university security guard checking student ID cards at the gate: catching a missing photo or expired sticker at the gate is instant, friendly, and prevents students from having their entry rejected inside the exam hall."

💡 Pro Tip: Code ko ratta mat maaro; imagine karo ki browser har tag ko visually kaise draw karta hai.

👨‍🏫3. Teacher Demonstration Code

See how regex testing executes on input events to toggle validation classes instantly.

Real-Time University Enrollment & Email Validator Enginehtml
<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 24px; }
    .form-box { max-width: 440px; margin: auto; background: #0c1328; border: 1px solid #1e293b; padding: 24px; border-radius: 12px; }
    .field { margin-bottom: 16px; }
    label { display: block; font-size: 13px; font-weight: bold; margin-bottom: 6px; }
    input { width: 100%; padding: 10px; background: #060c18; border: 1px solid #334155; color: #fff; border-radius: 6px; box-sizing: border-box; }
    input.valid { border-color: #10b981; }
    input.invalid { border-color: #ef4444; }
    .msg { font-size: 11px; margin-top: 4px; display: none; }
    .msg.error { color: #ef4444; display: block; }
    .msg.success { color: #10b981; display: block; }
    button { width: 100%; padding: 12px; background: #2563eb; color: #fff; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; }
  </style>
</head>
<body>
  <div class="form-box">
    <h3>📝 BCA Student Registration</h3>
    <form id="regForm">
      <div class="field">
        <label>Enrollment Number (9 Digits)</label>
        <input type="text" id="enrollInput" placeholder="e.g., 240189421" />
        <span class="msg" id="enrollMsg">Must be exactly 9 digits</span>
      </div>
      <div class="field">
        <label>University Email</label>
        <input type="email" id="emailInput" placeholder="name@university.edu" />
        <span class="msg" id="emailMsg">Enter a valid email address</span>
      </div>
      <button type="submit">Submit Registration</button>
    </form>
  </div>

  <script>
    const enrollInput = document.getElementById("enrollInput");
    const enrollMsg = document.getElementById("enrollMsg");
    const emailInput = document.getElementById("emailInput");
    const emailMsg = document.getElementById("emailMsg");

    const enrollRegex = /^\d{9}$/;
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

    function validateField(input, msg, regex, errorText) {
      if (regex.test(input.value.trim())) {
        input.className = "valid";
        msg.className = "msg success";
        msg.textContent = "✓ Valid";
        return true;
      } else {
        input.className = "invalid";
        msg.className = "msg error";
        msg.textContent = errorText;
        return false;
      }
    }

    enrollInput.addEventListener("input", () => {
      validateField(enrollInput, enrollMsg, enrollRegex, "Must be exactly 9 digits");
    });

    emailInput.addEventListener("input", () => {
      validateField(emailInput, emailMsg, emailRegex, "Invalid email format");
    });

    document.getElementById("regForm").addEventListener("submit", (e) => {
      e.preventDefault();
      const isEnrollValid = validateField(enrollInput, enrollMsg, enrollRegex, "Must be exactly 9 digits");
      const isEmailValid = validateField(emailInput, emailMsg, emailRegex, "Invalid email format");
      if (isEnrollValid && isEmailValid) {
        alert("Registration Submitted Successfully! 🎉");
      }
    });
  </script>
</body>
</html>

2. Hands-On Practical Lab: Follow Instructions in VS Code

Code like a professional software engineer! Follow the step-by-step instructions below in Visual Studio Code (VS Code) on your PC, test your output locally, and push to GitHub.

2 Coding Tasks
Interactive Coding TestAuto-Evaluates as you type

Day 36 Practical Task Test Studio

Test Score:0 / 2 Passed
1. Practical Task Specifications & Live Test Checklist:Type code below to pass tests
Task 1Implement Regex Character Class Checks

Use /[A-Z]/, /[0-9]/, and /[^A-Za-z0-9]/ to test password complexity.

⏳ WAITING
Task 2Listen on input Event

Attach an event listener to the password input for the "input" event for instant feedback.

⏳ WAITING
2. Type HTML & CSS Code:index.html
index.html
⚡ Real-Time Testing Active
Tab inserts 2 spaces • Live DOM refresh309 chars
Live Browser Output:
🔒 http://localhost:5500/index.html
Live
Renders live HTML & CSS typed on the left.
Interactive Bug Detective

Validating Exclusively on Form Submit Bug

Tap or click on the exact line below that contains the error:

Click any code line
⚠️ Broken Code Inspector
Tap buggy line
1
// ❌ Bug: User receives zero feedback until they click submit at the very end!
2
form.addEventListener("submit", (e) => {
3
e.preventDefault();
4
if (email.value.length < 5) {
5
alert("Email invalid");
6
}
7
});
Stuck? Need a detective clue before checking the solution?

Senior Developer Forensic Analysis:

Waiting until final form submission to alert users about simple typing errors causes poor UX. Modern applications validate on input or blur to offer immediate visual feedback as users type.

Golden Rule: Always validate code syntax and security attributes before pushing to GitHub!

📝Independent Practice: Assignment

📄 index.html

BCA Semester 1 Exam Admit Card Registration Portal

  • •Build a complete registration form with Student Name, 9-digit Enrollment Number, Email, 10-digit Phone, and Password.
  • •Validate each field in real-time with visual green/red borders and inline messages.
  • •Display a dynamic Password Strength Meter (Weak, Medium, Strong) with color progress bar.
  • •Disable the Submit button until all 5 fields pass validation.
Submission Evaluation Criteria: Push index.html and validator.js to your GitHub repository under day-36.
Exact Assignment Solution Code: index.html

Open Visual Studio Code on your PC (code .), create index.html, paste this complete step-by-step verified code, test in your browser, and push to your GitHub repo:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>BCA Day 36 - Form Validation</title>
  <style>
    body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 24px; }
    .card { max-width: 480px; margin: auto; background: #0c1328; border: 1px solid #1e293b; padding: 24px; border-radius: 12px; }
    .group { margin-bottom: 14px; }
    label { display: block; font-size: 13px; font-weight: bold; margin-bottom: 4px; }
    input { width: 100%; padding: 10px; background: #060c18; border: 1px solid #334155; color: #fff; border-radius: 6px; box-sizing: border-box; }
    input.valid { border-color: #10b981; }
    input.invalid { border-color: #ef4444; }
    .msg { font-size: 11px; color: #ef4444; margin-top: 3px; display: none; }
    .msg.show { display: block; }
    button { width: 100%; padding: 12px; background: #2563eb; color: #fff; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; margin-top: 10px; }
    button:disabled { background: #334155; cursor: not-allowed; opacity: 0.6; }
  </style>
</head>
<body>
  <div class="card">
    <h2>📋 BCA Admit Card Registration</h2>
    <form id="admitForm">
      <div class="group">
        <label>Full Name</label>
        <input type="text" id="name" placeholder="Rahul Sharma" />
        <span class="msg" id="nameMsg">Name must be at least 3 characters</span>
      </div>
      <div class="group">
        <label>Enrollment Number (9 Digits)</label>
        <input type="text" id="enroll" placeholder="240189211" />
        <span class="msg" id="enrollMsg">Must be exactly 9 digits</span>
      </div>
      <div class="group">
        <label>10-Digit Mobile Number</label>
        <input type="tel" id="phone" placeholder="9876543210" />
        <span class="msg" id="phoneMsg">Must be a valid 10-digit mobile number</span>
      </div>
      <button type="submit" id="submitBtn">Generate Admit Card</button>
    </form>
  </div>

  <script>
    const nameInput = document.getElementById("name");
    const enrollInput = document.getElementById("enroll");
    const phoneInput = document.getElementById("phone");
    const submitBtn = document.getElementById("submitBtn");

    function check() {
      const isName = nameInput.value.trim().length >= 3;
      const isEnroll = /^\d{9}$/.test(enrollInput.value.trim());
      const isPhone = /^[6-9]\d{9}$/.test(phoneInput.value.trim());

      nameInput.className = isName ? "valid" : (nameInput.value ? "invalid" : "");
      document.getElementById("nameMsg").className = isName || !nameInput.value ? "msg" : "msg show";

      enrollInput.className = isEnroll ? "valid" : (enrollInput.value ? "invalid" : "");
      document.getElementById("enrollMsg").className = isEnroll || !enrollInput.value ? "msg" : "msg show";

      phoneInput.className = isPhone ? "valid" : (phoneInput.value ? "invalid" : "");
      document.getElementById("phoneMsg").className = isPhone || !phoneInput.value ? "msg" : "msg show";

      submitBtn.disabled = !(isName && isEnroll && isPhone);
    }

    [nameInput, enrollInput, phoneInput].forEach(inp => inp.addEventListener("input", check));

    document.getElementById("admitForm").addEventListener("submit", (e) => {
      e.preventDefault();
      alert("✅ Admit Card Generated for " + nameInput.value);
    });

    check();
  </script>
</body>
</html>
Verified Assignment Code Solution (100% Tested & Ready to Run)

🎓4. Viva Check: Mandatory Conceptual Test

In the regular expression /^\d{10}$/, what do the ^ and $ symbols signify?

5. Mandatory Step: Push to GitHub to Unlock Next Lesson

Target Repo: html-css-projects

Windows 11 Terminal / VS Code
1$
mkdir day-36
Create a new project folder (day-36)
2$
cd day-36
Change working directory to day-36
3$
git checkout -b feature/day-36-form-validation
4$
git add index.html
5$
git commit -m "feat(day-36): implement client-side form validation and regex diagnostics"
Commit staged changes with a descriptive message
6$
git push origin feature/day-36-form-validation
Push local commits directly to your remote GitHub repository
⌨️ Paste into terminal:Ctrl + V✨ Word wrap active (no horizontal cutoff)
Completion Prerequisites VerificationIncomplete Steps
Google Login
✔ Required
VS Code Implementation
Step 4 Viva Check
Own GitHub Project
Required

Exact GitHub Setup Guide & Expected Structure

Day 36 Requirements

Follow these exact folder and file names to prevent verification errors.

1. GitHub Repository
html-css-projects
Must be set to Public
2. Exact FolderNEW
day-36/ or bca-day-36/
Create inside repo root
3. Exact File NameREQUIRED
index.html
⚠️ No spaces or custom names
4. What to Submit Below
https://github.com/YOU/html-css-projects
Or direct link to index.html
Terminal Commands to Create & Push Day 36
1$
# 1. Enter your repository directory
2$
cd html-css-projects
Change working directory to html-css-projects
3$
# 2. Create the exact folder for Day 36
4$
mkdir day-36
Create a new project folder (day-36)
5$
cd day-36
Change working directory to day-36
6$
# 3. Create your code file: index.html
7$
# (Write your Day 36 homework code inside index.html)
8$
# 4. Save, stage, commit and push to GitHub:
9$
git add .
Stage all modified files and new assets for commit
10$
git commit -m "Day 36: Client-Side Form Validation & Real-Time Regex Diagnostics"
Commit staged changes with a descriptive message
11$
git push origin main
Push local commits directly to your remote GitHub repository
⌨️ Paste into terminal:Ctrl + V✨ Word wrap active (no horizontal cutoff)
How to Avoid "Could not find your practical code file" Errors:
1.Use Lowercase index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.
2.Separate Day Folders: Create a new folder day-36/ for today so you don't overwrite previous days.
3.Ensure Public Visibility: If your GitHub repo is Private, automated validation cannot inspect your code. Set it to Public.
4.Check on GitHub Website: Before clicking "Verify", open your repo in Google Chrome to confirm your files were pushed to branch main.
📁 github.com/YOUR_USERNAME/html-css-projects
Branch: main
README.md# BCA Practical Portfolio overview
day-01/Day 1 Prior Lesson
└──index.html
day-02/Day 2 Prior Lesson
└──index.html
day-03/Day 3 Prior Lesson
└──index.html
day-04/Day 4 Prior Lesson
└──index.html
day-05/Day 5 Prior Lesson
└──index.html
day-06/Day 6 Prior Lesson
└──index.html
day-07/Day 7 Prior Lesson
└──index.html
day-08/Day 8 Prior Lesson
└──index.html
day-09/Day 9 Prior Lesson
└──index.html
day-10/Day 10 Prior Lesson
└──index.html
└──styles.css
day-11/Day 11 Prior Lesson
└──index.html
day-12/Day 12 Prior Lesson
└──index.html
day-13/Day 13 Prior Lesson
└──index.html
day-14/Day 14 Prior Lesson
└──index.html
day-15/Day 15 Prior Lesson
└──index.html
day-16/Day 16 Prior Lesson
└──index.html
day-17/Day 17 Prior Lesson
└──index.html
day-18/Day 18 Prior Lesson
└──index.html
day-19/Day 19 Prior Lesson
└──index.html
day-20/Day 20 Prior Lesson
└──index.html
└──styles.css
day-21/Day 21 Prior Lesson
└──index.html
day-22/Day 22 Prior Lesson
└──index.html
day-23/Day 23 Prior Lesson
└──index.html
day-24/Day 24 Prior Lesson
└──index.html
day-25/Day 25 Prior Lesson
└──index.html
day-26/Day 26 Prior Lesson
└──index.html
day-27/Day 27 Prior Lesson
└──index.html
day-28/Day 28 Prior Lesson
└──index.html
day-29/Day 29 Prior Lesson
└──index.html
day-30/Day 30 Prior Lesson
└──index.html
└──styles.css
day-31/Day 31 Prior Lesson
└──index.html
day-32/Day 32 Prior Lesson
└──index.html
day-33/Day 33 Prior Lesson
└──index.html
day-34/Day 34 Prior Lesson
└──index.html
day-35/Day 35 Prior Lesson
└──index.html
day-36/✨ CREATE THIS FOLDER FOR TODAY (Day 36)
└──index.htmlMust contain:
Sequential Progression Enforced

You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 36 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 35: Dynamic Modal Dialogs, Overlay Mechanics & Keyboard Accessibility first.

Complete Day 35 First
Day 35: Dynamic Modal Dialogs, Overlay Mechanics & Keyboard Accessibility
WhatsApp
Curriculum & Practical Systems Authored by Er. Manoj Kumar
NextSem Academy • BCA Practical Learning Portal