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

var config = {
    map: {
        '*': {
            vky_customjs:      'Vky_Core/js/vky_custom'
        }
    }
};


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

define([
    "jquery",
    "jquery/ui",
    'mage/validation'
], function($) {
    "use strict";
    console.log('vky_custom.js is loaded!!');
        //creating jquery widget
        $.widget('vky_custom.js', {
            _create: function() {
                this._bind();
            },

            /**
             * Event binding, will monitor change, keyup and paste events.
             * @private
             */
            _bind: function () {
                this._on(this.element, {
                    'change': this.validateField,
                    'keyup': this.validateField,
                    'paste': this.validateField,
                    'click': this.validateField,
                    'focusout': this.validateField,
                    'focusin': this.validateField,
                });
            },

            validateField: function () {
                $.validator.validateSingleElement(this.element);
            },

        });

    return $.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

$('#firstname').addClass('v-validate');
$('#lastname').addClass('v-validate');

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