Web component / Examples

<form-matching-fields>

Add a mismatch message to the second of two text-type inputs without replacing their existing validation. See the README for installation details and API documentation.

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.

The code shows native forms with matching validation. The live examples also use a demo-only helper to keep feedback visible after submission: it displays the mismatch message or a reminder to check required values and formats. The component itself doesn’t create this text region or move focus; the browser handles invalid-field focus.

Password Confirmation

Enter two different, nonempty passwords, then submit. The browser focuses “Password again” and shows the mismatch message. Make the values match and submit again to see the demo’s confirmation. Empty fields use native required validation instead.

Password + Password again

<form>
<form-matching-fields>
  <label for="password">Password</label>
  <input id="password" type="password" required />

  <label for="password-again">Password again</label>
  <input id="password-again" type="password" required />
</form-matching-fields>
  <button type="submit">Submit</button>
</form>

Email Verification

Use type="email" for email confirmation. Enter two different, valid email addresses, then submit to see matching validation. An invalid address in the second field keeps its native format error instead of a mismatch message.

Email + Verify email

<form>
<form-matching-fields>
  <label for="email">Email</label>
  <input id="email" type="email" required />

  <label for="email-again">Verify email</label>
  <input id="email-again" type="email" required />
</form-matching-fields>
  <button type="submit">Submit</button>
</form>

Custom Message

Set validation-message to use your application’s vocabulary. {label_1} and {label_2} become the field labels, not their values. See the label reference for fallback order.

Custom mismatch copy

<form>
<form-matching-fields validation-message="Please make sure {label_2} matches {label_1}.">
  <label for="email-custom">Email</label>
  <input id="email-custom" type="email" required />

  <label for="email-custom-again">Verify email</label>
  <input id="email-custom-again" type="email" required />
</form-matching-fields>
  <button type="submit">Submit</button>
</form>

Localized Message (Hindi)

Translate the mismatch message and field labels together. This form also authors its submit label and demo feedback in Hindi and sets lang="hi". Native browser validation messages still follow the browser’s language.

Hindi validation message

<form lang="hi">
<form-matching-fields validation-message="{label_1} और {label_2} का मान समान होना चाहिए।">
  <label for="password-hi">पासवर्ड</label>
  <input id="password-hi" type="password" required />

  <label for="password-hi-again">पासवर्ड फिर से</label>
  <input id="password-hi-again" type="password" required />
</form-matching-fields>
  <button type="submit">जमा करें</button>
</form>

API Reference

For complete documentation of behavior and browser support, see the README.