BCA Student Stories & UpdatesLive
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.
Day 36 Step-by-Step Practical Flow
🎯1. What You Will Learn Today
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.
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.
"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."
👨🏫3. Teacher Demonstration Code
See how regex testing executes on input events to toggle validation classes instantly.
<!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.
Day 36 Practical Task Test Studio
Use /[A-Z]/, /[0-9]/, and /[^A-Za-z0-9]/ to test password complexity.
Attach an event listener to the password input for the "input" event for instant feedback.
Validating Exclusively on Form Submit Bug
Tap or click on the exact line below that contains the error:
Click any code line// ❌ Bug: User receives zero feedback until they click submit at the very end!form.addEventListener("submit", (e) => { e.preventDefault(); if (email.value.length < 5) { alert("Email invalid"); }});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.
📝Independent Practice: Assignment
📄 index.htmlBCA 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.
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>🎓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
Exact GitHub Setup Guide & Expected Structure
Day 36 RequirementsFollow these exact folder and file names to prevent verification errors.
index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.day-36/ for today so you don't overwrite previous days.main.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