0

how to validate customer registration form in magento 2

Spread the love

I was working on a project on magento 2 where I need to validate registration form. I want to use the event keyup for inputs and also wanna change the default message.after searching internet i found this below solution,for this you have to add a new js file using requirejs-config.js. But i created a new module. Module files are as below.


app\code\Vky\Core\registration.php


app\code\Vky\Core\etc\module.xml


app\code\Vky\Core\view\frontend\requirejs-config.js


app\code\Vky\Core\view\frontend\web\js\vky_custom.js

Now open register.phtml. At the end of the file add below things.

And then, for example, you want to validate email. Find input tag for email and add class v-validate. Like this

So any input with class v-validate will be validated on events like keyup, change, click, focusout, etc. I added a class to all input tags.

For firstname and lastname in register.phtml above this line var dataForm = $('#form-validate'); I added

That’s all I did to solve my problem. May be this can help someone.

Leave a Reply

Your email address will not be published. Required fields are marked *