Created
April 20, 2026 11:08
-
-
Save andxbes/9114e34ca44d76be1730505408fba5e4 to your computer and use it in GitHub Desktop.
Custom validate Ninja Form email field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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