Laravel validation rule that checks if a string is offensive.

v1.3.0 2020-03-21 20:47 UTC

This package is auto-updated.

Last update: 2024-05-22 06:02:30 UTC


This package provides a Laravel validation rule that checks if a string is offensive. It can be useful to check user supplied data that may be publicly displayed, such as usernames or comments.

Laravel Offensive Validation Rule usage

68747470733a2f2f7472617669732d63692e6f72672f446976696e654f6d6567612f6c61726176656c2d6f6666656e736976652d76616c69646174696f6e2d72756c652e7376673f6272616e63683d6d6173746572 Coverage Status StyleCI


To install, just run the following Composer command.

composer require divineomega/laravel-offensive-validation-rule

Please note that this package requires Laravel 5.5 or above.


The following code snippet shows an example of how to use the offensive validation rule.

use DivineOmega\LaravelOffensiveValidationRule\Offensive;

    'username' => ['required', new Offensive],

Custom word lists

If the defaults are too strict (or not strict enough), you can optionally specify a custom list of offensive words and custom whitelist. Below is an example of using a custom blacklist and whitelist.

use DivineOmega\LaravelOffensiveValidationRule\Offensive;
use DivineOmega\IsOffensive\OffensiveChecker;

$blacklist = ['moist', 'stinky', 'poo'];
$whitelist = ['poop'];

    'username' => ['required', new Offensive(new OffensiveChecker($blacklist, $whitelist))],