Magento 2 Form Validation: How To Add Custom Validate Field Last Updated on 4 August 20254 August 2025 Mark Mac Magento Running a Magento 2 website can sometimes feel like assembling a jigsaw puzzle – every piece needs to fit just right. One tricky piece that often stumps folks is the ‘Form Validation’ – specifically, adding a custom validate field. But fear not! In today blog post, we will show you three easy-to-follow steps to add a custom validate field in your Magento 2 form. Let’s get started! Table of Contents Toggle Step 1: Add Custom Validate MethodStep 2: Bind Custom Validation Method Name To A Javascript File By Using RequireJsStep 3: Create Javascript File To Confirm Validate Step 1: Add Custom Validate Method First, in the data-mage-init attribute, you must add a custom method named tigrenValidateMethod. <form class=”form contact”action=”<?= $block->escapeUrl($block->getFormAction()) ?>”id=”contact-form”method=”post”data-hasrequired=”<?= $block->escapeHtmlAttr(__(‘* Required Fields’)) ?>”data-mage-init='{“validation”:{},“tigrenValidateMethod”:{}}’> Then, you must add your custom field into the form: <div class="field name required"> <label class="label" for="field_tigren"><span>Field Tigren Test(Tigren)</span></label> <div class="control"> <input name="field_tigren" id="field_tigren" value="" class="input-text required tigren" type="text"/> </div> </div> Here we’ve just added a class named tigren to validate field. Step 2: Bind Custom Validation Method Name To A Javascript File By Using RequireJs app/design/frontend/Tigren/tigren/requirejs-config.js var config = { map: { "*": { tigrenValidateMethod: "js/tigrenValidateField" } } }; Step 3: Create Javascript File To Confirm Validate app/design/frontend/Tigren/tigren/web/js/tigrenValidateField.js define([ 'jquery', 'jquery/ui', 'jquery/validate', 'mage/translate' ], function($){ 'use strict'; return function() { $.validator.addMethod( "tigren", function(value, element) { return this.optional(element) || /^Tigren/.test(value); }, $.mage.__("Type 'Tigren' in this field.") ); } }); Those are three simple steps to add the custom validate field into Magento 2 form. We hope that this post has been helpful to you. Mark Mac Mark Mac is our adept Project Lead at Tigren. A skilled problem solver and expert developer, Mark's leadership in web/app projects is evident through his strategic thinking and technical prowess. Committed to propelling businesses forward in the dynamic tech landscape, Mark ensures excellence in every endeavor. Share Table of Contents Toggle Step 1: Add Custom Validate MethodStep 2: Bind Custom Validation Method Name To A Javascript File By Using RequireJsStep 3: Create Javascript File To Confirm Validate