Skip to content

Instantly share code, notes, and snippets.

@andxbes
Created April 20, 2026 11:08
Show Gist options
  • Select an option

  • Save andxbes/9114e34ca44d76be1730505408fba5e4 to your computer and use it in GitHub Desktop.

Select an option

Save andxbes/9114e34ca44d76be1730505408fba5e4 to your computer and use it in GitHub Desktop.
Custom validate Ninja Form email field
jQuery(document).ready(function ($) {
if (typeof Marionette !== 'undefined') {
const banned_email_domains = [
'@gmail',
'@ymail',
'@live',
'@yahoo',
'@yandex',
'@hotmail',
'@protonmail',
'@hotmail',
'@outlook',
'@ukr',
'@mail',
'@icloud',
'@test',
'@user',
];
var myCustomFieldController = Marionette.Object.extend({
initialize: function () {
var submitChannel = Backbone.Radio.channel('submit');
this.listenTo(submitChannel, 'validate:field', this.validateRequired);
var fieldsChannel = Backbone.Radio.channel('fields');
this.listenTo(fieldsChannel, 'change:modelValue', this.validateRequired);
},
validateRequired: function (model) {
if (model.get('type') === 'email') {
let value = model.get('value');
if (banned_email_domains.some((banned_domain) => value.includes(banned_domain))) {
Backbone.Radio.channel('fields').request('add:error', model.get('id'), 'email-domain-validate-field-error', 'Please use your business email');
} else {
Backbone.Radio.channel('fields').request('remove:error', model.get('id'), 'email-domain-validate-field-error');
}
} else {
return;
}
}
});
new myCustomFieldController();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment