Would you like to verify that users enter the same information in two different fields? While WPForms includes built-in email confirmation, you can extend this functionality to other field types like Phone, Address, or any other field where you need to confirm user input.
This guide will show you how to implement field comparison validation using a simple code snippet.
Setting Up the Form
To begin, create a new form or edit an existing one. For this example, we’ll create a form with two Phone fields to demonstrate field comparison validation. The first field will collect the phone number, and the second field will be for confirmation.
If you need help creating a new form, please review our guide on creating your first form.
Adding the Code Snippet
Next, you’ll need to add the code snippet that handles the field comparison validation. If you’re not sure where to add custom code to your site, please check our guide on adding custom code.
The following snippet will compare two Phone fields and display an error message if they don’t match:
You’ll need to customize three key values in the code:
- On line 10, replace
1000
with your form ID - On line 15, replace
3
with your first Phone field ID - On line 18, replace
4
with your second Phone field ID
If you need help finding your form and field IDs, please check our guide on how to find form and field IDs.
And that’s it! By using field comparisons, you can ensure the data being entered in your forms is verified. Would you like to conditionally display the Submit button? Take a look at our tutorial on How to Conditionally Show the Submit Button.