Magento 2 How to extend rules.js to add custom validation rules?

you have to set rules.js inside your theme.

First create folder inside your theme Magento_Ui if its already exist then skip it.

keep file into below location from core module.

app/code/Package/themename/Magento_Ui/web/js/lib/validation/rules.js

Remove var folder. Remove pub/static folder contents and run deploy command,

php bin/magento setup:static-content:deploy


This is the best way to add a new rule without override the file rules.js and use on LayoutProcessor.php or jsLayout.

define(
    [
        'jquery',
        'Magento_Ui/js/lib/validation/validator'
    ],function ($,validator) {
    "use strict";
    return validator.addRule('validade-name-of-validation',
        function (value) {
            return /* your function */
        }, $.mage.__('Your error message.')
    );
});

Enjoy!