JavaScript Widget
Usage
Basic Initialization
After including the library, initialize the Blocker
to start protecting your forms:
import { Blocker } from "disposable-email-blocker"; // Initialize with default settings new Blocker();javascript
Alternatively, if included via a CDN:
<script src="https://cdn.jsdelivr.net/npm/disposable-email-blocker/disposable-email-blocker.min.js"></script> <script> new Disposable.Blocker(); </script>html
Customizing Error Messages
You can customize the error messages displayed when a disposable or webmail email is detected:
new Blocker({ messages: { disposable: "Disposable email addresses are not allowed.", webmail: "Please use your professional email address.", }, });javascript
Blocking Webmail Services
By default, the blocker focuses on disposable email services. To extend protection to webmail services (e.g., Gmail, Yahoo), enable the blockWebmail
option:
new Blocker({ blockWebmail: true, });javascript
Blocker options
The Blocker constructor parameter.
const options = { apiUrl: "string", data: "TombaStatusResponse[]", disposable: { message: "string", }, webmail: { message: "string", block: false, }, emailError: { className: "string", style: `string`, }, }; new Disposable.Blocker(options);javascript
Custom API URL
const options = { apiUrl: "string", }; new Disposable.Blocker(options);javascript
Custom DATA
This will stop API call
const options = { data: [ { domain: "coronafleet.com", webmail: true, disposable: false, }, ], }; new Disposable.Blocker(options);javascript
Event
use the on()
API method.
Available Event name done
the Content is revealed on onInput
const blocker = new Blocker(); blocker.on("done", (e) => { if (e.detail.disposable) { alert(blocker.options.disposable.message); } });javascript