Matching validation is loading. Fields remain editable; native required and email checks still work.
These forms don’t send or store your entries. Without JavaScript, the browser checks required fields and email syntax, but doesn’t compare values. Always verify matching values on the server.
Enter two different, nonempty passwords, then submit the first form. Matching adds an error to the second field; the browser focuses it. Make the values match and submit again. The live examples also use a demo-only helper for persistent feedback. The code shows the native forms, not that helper. See the main walkthrough for matching, message, and label options.
Automatic registration
Importing define.js registers the element. The
exported helper also guards repeated calls.
import { defineComponentName } from 'https://unpkg.com/@aarongustafson/form-matching-fields@latest/define.js?module';
defineComponentName();
Password confirmation
<form>
<form-matching-fields>
<label for="password-unpkg">Password</label>
<input id="password-unpkg" type="password" required>
<label for="password-unpkg-again">Password again</label>
<input id="password-unpkg-again" type="password" required>
</form-matching-fields>
<button type="submit">Submit</button>
</form>
Email verification
<form>
<form-matching-fields>
<label for="email-unpkg">Email</label>
<input id="email-unpkg" type="email" required>
<label for="email-unpkg-again">Verify email</label>
<input id="email-unpkg-again" type="email" required>
</form-matching-fields>
<button type="submit">Submit</button>
</form>
Custom message
Use validation-message with
{label_1} and {label_2} to match
your application’s vocabulary before translating it.
<form>
<form-matching-fields validation-message="Please make sure {label_2} matches {label_1}.">
<label for="email-unpkg-custom">Email</label>
<input id="email-unpkg-custom" type="email" required>
<label for="email-unpkg-custom-again">Verify email</label>
<input id="email-unpkg-custom-again" type="email" required>
</form-matching-fields>
<button type="submit">Submit</button>
</form>
Localized message (Hindi)
Translate the labels, mismatch message, and demo feedback. Native required messages follow the browser’s language.
<form lang="hi">
<form-matching-fields validation-message="{label_1} और {label_2} का मान समान होना चाहिए।">
<label for="password-unpkg-hi">पासवर्ड</label>
<input id="password-unpkg-hi" type="password" required>
<label for="password-unpkg-hi-again">पासवर्ड फिर से</label>
<input id="password-unpkg-hi-again" type="password" required>
</form-matching-fields>
<button type="submit">जमा करें</button>
</form>