Effortlessly test strings against any array of disallowed strings. Supports fnmatch
wildcards, like * and ?.
accentinteractive/disallowlister
contains both a facade Disallowlister
and custom validation rule disallowlister
. You can set a default array of disallowed strings in config, or add and remove disallowed strings using Disallowlister:add()
and Disallowlister:remove()
This Laravel-specific package tests a string against a disallowlist. It is a Laravel implementation of the platform agnostic accentinteractive/disallowlister
.
If you are looking for a framework agnostic implementation, see https://github.com/accentinteractive/disallowlister
For a list of all options, see https://github.com/accentinteractive/disallowlister#readme.
The isDisallowed()
method can use wildcards, like * and ?.
Under the hood, accentinteractive/disallowtester
uses fnmatch()
, so you can use the same wildcards as in that php function (the globbing wildcard patterns):
-
*sex*
disallows sex, sexuality and bisexual. -
cycle*
disallows cycle and cycles, but not bicycle. -
m[o,u]m
disallows mom and mum, but allows mam. -
m?n
disallows man and men, but allows moon.
You can install the package via composer:
composer require accentinteractive/laravel-disallowlister
Optionally you can publish the config file with:
php artisan vendor:publish --provider="Accentinteractive\LaravelDisallowlister\LaravelDisallowlisterServiceProvider" --tag="config"
- Publish the config file, running
php artisan vendor:publish --provider="Accentinteractive\LaravelDisallowlister\LaravelDisallowlisterServiceProvider" --tag="config"
- Set an default array of disalllowed strings in
disallowlister.lists.default
- If you wish to use more than one disallowlist, you can add additional arrays of disalllowed strings to
disallowlister.lists
, likedisallowlister.lists.my_list
By default, the validator uses the default disallow list.
// Use the disallowlist validator with the default disallowlist.
$rules = [
'user_input' => 'disallowlister'
];
However, you can also pass to the validator which disallowlist to use.
// Use the disallowlist validator with the my_list disallowlist.
$rules = [
'user_input' => 'disallowlister:default',
'user_emails' => 'disallowlister:my_email_list'
];
By default, matching is not case sensitive. You can set case sensitivity in confg
config(['disallowlister.is_case_sensitive' => true]);
By default the entire string is checked. You can set to check word for word in config.
config(['disallowlister.match_word_for_word' => true]);
use Accentinteractive\LaravelDisallowlister\Facades\Disallowlister;
// Call the facade directly, using the default disallowlist
DisallowLister::isDisallowed('Earn $4,000 A DAY working from HOME!!!');
// Call the facade directly, using a specific disallowlist
DisallowLister::setDisallowList(config('disallowlister.lists.mylist'))
->isDisallowed('Earn $4,000 A DAY working from HOME!!!');
// Add and remove items on the facade
DisallowLister::add('foo')
->add(['*bar*', 'b?t'])
->remove('b?t')
->isDisallowed('Earn $4,000 A DAY working from HOME!!!');
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.