Bootstrap 5 Registration Form with Validation
A player registration form with floating labels, a country select, pill-style interest toggles and live client-side validation.
<section class="wdw-stage">
<div class="container" style="max-width:1000px">
<div class="wdw-card overflow-hidden">
<div class="row g-0">
<div class="col-lg-5 wdw-aurora p-4 p-md-5 d-flex flex-column justify-content-between gap-4">
<div>
<span class="wdw-eyebrow text-white-50">Registration</span>
<h2 class="wdw-heading h2 mt-1 mb-2 text-white">Join the league</h2>
<p class="text-white-50 mb-4">Register as a player in under a minute. Step 1 of 1: your account and a few details.</p>
</div>
<ul class="list-unstyled mb-0 small">
<li class="d-flex gap-2 align-items-start mb-2"><svg class="flex-shrink-0 mt-1" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg><span>Weekly fixtures and live standings</span></li>
<li class="d-flex gap-2 align-items-start mb-2"><svg class="flex-shrink-0 mt-1" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg><span>Free kit for every registered player</span></li>
<li class="d-flex gap-2 align-items-start mb-2"><svg class="flex-shrink-0 mt-1" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg><span>Find a team near you, any skill level</span></li>
</ul>
</div>
<form class="col-lg-7 p-4 p-md-5" id="regForm" novalidate>
<fieldset>
<legend class="wdw-eyebrow mb-3">Account</legend>
<div class="row g-3">
<div class="col-12"><div class="form-floating"><input type="email" class="form-control" id="rgEmail" placeholder="Email address" aria-describedby="rgEmailFb" required autocomplete="email"><label for="rgEmail">Email address</label><div class="invalid-feedback" id="rgEmailFb">Enter a valid email address.</div></div></div>
<div class="col-sm-6"><div class="input-group has-validation"><div class="form-floating"><input type="password" class="form-control" id="rgPass" placeholder="Password" minlength="8" autocomplete="new-password" aria-describedby="rgPassFb rgStrengthText" required><label for="rgPass">Password</label><div class="invalid-feedback" id="rgPassFb">Use at least 8 characters.</div></div><button type="button" class="btn btn-outline-secondary text-body" id="rgShow" aria-label="Show passwords" aria-pressed="false"><svg class="eye-on" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/></svg><svg class="eye-off d-none" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3l18 18M10.6 5.1A10 10 0 0 1 12 5c6.5 0 10 7 10 7a17 17 0 0 1-3.2 4M6.6 6.6A17 17 0 0 0 2 12s3.5 7 10 7c1.7 0 3.2-.4 4.5-1M9.9 9.9a3 3 0 0 0 4.2 4.2"/></svg></button></div>
<div class="progress mt-2" style="height:6px" aria-hidden="true"><div class="progress-bar" id="rgStrength" style="width:0"></div></div>
<div class="form-text" id="rgStrengthText">Password strength: none</div></div>
<div class="col-sm-6"><div class="form-floating"><input type="password" class="form-control" id="rgPass2" placeholder="Repeat password" aria-describedby="rgPass2Fb" required autocomplete="new-password"><label for="rgPass2">Repeat password</label><div class="invalid-feedback" id="rgPass2Fb">Passwords do not match.</div></div></div>
</div>
</fieldset>
<fieldset class="mt-4">
<legend class="wdw-eyebrow mb-3">About you</legend>
<div class="row g-3">
<div class="col-sm-6"><div class="form-floating"><input type="text" class="form-control" id="rgFirst" placeholder="First name" aria-describedby="rgFirstFb" required autocomplete="given-name"><label for="rgFirst">First name</label><div class="invalid-feedback" id="rgFirstFb">Please enter your first name.</div></div></div>
<div class="col-sm-6"><div class="form-floating"><input type="text" class="form-control" id="rgLast" placeholder="Last name" aria-describedby="rgLastFb" required autocomplete="family-name"><label for="rgLast">Last name</label><div class="invalid-feedback" id="rgLastFb">Please enter your last name.</div></div></div>
<div class="col-sm-4"><div class="form-floating"><input type="number" class="form-control" id="rgAge" placeholder="Age" aria-describedby="rgAgeFb" required min="12" max="99"><label for="rgAge">Age</label><div class="invalid-feedback" id="rgAgeFb">Age must be 12 to 99.</div></div></div>
<div class="col-sm-8"><div class="form-floating"><select class="form-select" id="rgCountry" aria-describedby="rgCountryFb" required><option value="" selected></option><option>United States</option><option>United Kingdom</option><option>Canada</option><option>Germany</option><option>Australia</option></select><label for="rgCountry">Country</label><div class="invalid-feedback" id="rgCountryFb">Select a country.</div></div></div>
<div class="col-12"><div class="form-floating"><input type="text" class="form-control" id="rgAddress" placeholder="Address" aria-describedby="rgAddressFb" required autocomplete="street-address"><label for="rgAddress">Address</label><div class="invalid-feedback" id="rgAddressFb">Please enter your address.</div></div></div>
</div>
</fieldset>
<fieldset class="mt-4">
<legend class="fs-6 fw-semibold mb-2">Interests</legend>
<div class="d-flex flex-wrap gap-2">
<input type="checkbox" class="btn-check" id="rgTravel" autocomplete="off"><label class="btn btn-outline-primary rounded-pill" for="rgTravel"><svg class="pill-check" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>Travel</label><input type="checkbox" class="btn-check" id="rgReading" autocomplete="off"><label class="btn btn-outline-primary rounded-pill" for="rgReading"><svg class="pill-check" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>Reading</label><input type="checkbox" class="btn-check" id="rgSwim" autocomplete="off"><label class="btn btn-outline-primary rounded-pill" for="rgSwim"><svg class="pill-check" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>Swimming</label>
</div>
</fieldset>
<div class="d-flex flex-column flex-sm-row gap-2 mt-4">
<button type="submit" class="btn btn-primary rounded-pill flex-fill">Create account</button>
<button type="reset" class="btn btn-link link-body-emphasis text-decoration-none rounded-pill px-4">Reset</button>
</div>
<div class="alert alert-success mt-3 mb-0 py-2" id="regOk" role="status" hidden>Thanks! Your registration was received.</div>
</form>
</div>
</div>
</div>
</section>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.pill-check { display: none; }
.btn-check:checked + .btn .pill-check { display: inline-block; }
.btn-check:checked + .btn { --bs-btn-color: #fff; }
[data-bs-theme="dark"] .btn-check:checked + .btn { --bs-btn-active-color: #0f1117; color: #0f1117; }
.input-group .form-floating:not(:last-child) > .form-control { border-top-right-radius: 0; border-bottom-right-radius: 0; }
#rgShow { min-width: 48px; }
#rgStrength { transition: width .25s, background-color .25s; }
legend.wdw-eyebrow { float: none; width: auto; font-size: .75rem; }
@media (prefers-reduced-motion: reduce) { #rgStrength { transition: none; } }
function initRegistrationForm() {
const form = document.getElementById('regForm');
if (!form) return;
const ok = document.getElementById('regOk');
const pass = document.getElementById('rgPass'), pass2 = document.getElementById('rgPass2');
const bar = document.getElementById('rgStrength'), barText = document.getElementById('rgStrengthText');
const show = document.getElementById('rgShow');
const fields = form.querySelectorAll('input.form-control, select.form-select');
const checkMatch = () => pass2.setCustomValidity(pass2.value && pass2.value !== pass.value ? 'mismatch' : '');
const mark = f => {
checkMatch();
const valid = f.checkValidity();
f.classList.toggle('is-invalid', !valid);
f.classList.toggle('is-valid', valid && f.value !== '');
};
const strength = () => {
const v = pass.value;
const score = v ? Math.min(4, [v.length >= 8, /[A-Z]/.test(v) && /[a-z]/.test(v), /\d/.test(v), /[^A-Za-z0-9]/.test(v)].filter(Boolean).length) : 0;
const names = ['none', 'weak', 'fair', 'good', 'strong'];
const cls = ['', 'bg-danger', 'bg-warning', 'bg-info', 'bg-success'];
bar.style.width = score * 25 + '%';
bar.className = 'progress-bar ' + cls[score];
barText.textContent = 'Password strength: ' + names[score];
};
fields.forEach(f => {
f.addEventListener('blur', () => mark(f));
f.addEventListener('input', () => { if (f.classList.contains('is-invalid') || f.classList.contains('is-valid')) mark(f); });
});
pass.addEventListener('input', () => { strength(); if (pass2.value) mark(pass2); });
show.addEventListener('click', () => {
const on = pass.type === 'password';
[pass, pass2].forEach(i => { i.type = on ? 'text' : 'password'; });
show.setAttribute('aria-pressed', on);
show.setAttribute('aria-label', on ? 'Hide passwords' : 'Show passwords');
show.querySelector('.eye-on').classList.toggle('d-none', on);
show.querySelector('.eye-off').classList.toggle('d-none', !on);
});
form.addEventListener('submit', e => {
e.preventDefault();
ok.hidden = true;
fields.forEach(mark);
const bad = form.querySelector(':invalid');
if (bad) bad.focus(); else ok.hidden = false;
});
form.addEventListener('reset', () => {
fields.forEach(f => f.classList.remove('is-invalid', 'is-valid'));
ok.hidden = true;
setTimeout(strength);
});
}
initRegistrationForm();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.