Additional validation rules for the Laravel framework
marshmallow/validation is a Laravel package for additional validation rules for the laravel framework.
It currently has 0 GitHub stars and 4.443 downloads on Packagist (latest version v4.4.0).
Install it with composer require marshmallow/validation.
Discover more Laravel packages by marshmallow
or browse all Laravel packages to compare alternatives.
Last updated
marshmallow-validation is an extension library for Laravel's own validation
system. The package adds rules to validate data like IBAN, BIC, ISBN,
creditcard numbers and more.
[!important] This package was originally forked from intervention/validation. Since we were making many opinionated changes and the owner archived the repository, we decided to continue development in our own version rather than submitting pull requests that might not benefit all users of the original package. You're welcome to use this package, we're actively maintaining it. If you encounter any issues, please don't hesitate to reach out.
You can install this package quick and easy with Composer.
Require the package via Composer:
$ composer require marshmallow/validation
The Validation library is built to work with the Laravel Framework (>=10). It comes with a service provider, which will be discovered automatically and registers the validation rules into your installation. The package provides 30 additional validation rules including multi language error messages, which can be used like Laravel's own validation rules.
use Illuminate\Support\Facades\Validator;
use Marshmallow\Validation\Rules\Creditcard;
use Marshmallow\Validation\Rules\Hexadecimalcolor;
use Marshmallow\Validation\Rules\Username;
$validator = Validator::make($request->all(), [
'color' => new Hexadecimalcolor([3, 6]), // pass rule as object
'number' => ['required', 'creditcard'], // or pass rule as string
'name' => 'required|min:3|max:20|username', // combining rules works as well
]);
Add the corresponding key to /resources/lang/<language>/validation.php like this:
// example
'iban' => 'Please enter IBAN number!',
Or add your custom messages directly to the validator like described in the docs.
The following validation rules are available with this package.
The field under validation must be Base64 encoded.
public Marshmallow\Validation\Rules\Base64::__construct()
Checks for a valid Business Identifier Code (BIC).
public Marshmallow\Validation\Rules\Bic::__construct()
The field under validation must be a formated in Camel case.
public Marshmallow\Validation\Rules\Camelcase::__construct()
Check if the value is a Classless Inter-Domain Routing notation (CIDR).
public Marshmallow\Validation\Rules\Cidr::__construct()
The field under validation must be a valid creditcard number.
public Marshmallow\Validation\Rules\Creditcard::__construct()
The field under validation must be a valid Data URI.
public Marshmallow\Validation\Rules\DataUri::__construct(?array $media_types = null)
The field under validation must be a well formed domainname.
public Marshmallow\Validation\Rules\Domainname::__construct()
The field under validation must be a valid Dutch phone number, optionally including a +31, 0031 or 0 country prefix.
public Marshmallow\Validation\Rules\Dutchphonenumber::__construct()
Checks for a valid European Article Number.
public Marshmallow\Validation\Rules\Ean::__construct(array $lengths = [8, 13])
length
Optional integer length (8 or 13) to check only for EAN-8 or EAN-13.
Checks for a valid Global Trade Item Number.
public Marshmallow\Validation\Rules\Gtin::__construct(array $lengths = [8, 12, 13, 14])
length
Optional array of allowed lengths to check only for certain types (GTIN-8, GTIN-12, GTIN-13 or GTIN-14).
The field under validation must be a valid hexadecimal color code.
public Marshmallow\Validation\Rules\Hexadecimalcolor::__construct(array $lengths = [3, 4, 6, 8])
length
Optional length as integer to check only for shorthand (3 or 4 characters) or full hexadecimal (6 or 8 characters) form.
The field under validation must be free of any html code.
public Marshmallow\Validation\Rules\HtmlClean::__construct()
Checks for a valid International Bank Account Number (IBAN).
public Marshmallow\Validation\Rules\Iban::__construct()
The field under validation must be a International Mobile Equipment Identity (IMEI).
public Marshmallow\Validation\Rules\Imei::__construct()
The field under validation must be a valid International Standard Book Number (ISBN).
public Marshmallow\Validation\Rules\Isbn::__construct(array $lengths = [10, 13])
length
Optional length parameter as integer to check only for ISBN-10 or ISBN-13.
Checks for a valid International Securities Identification Number (ISIN).
public Marshmallow\Validation\Rules\Isin::__construct()
Checks for a valid International Standard Serial Number (ISSN).
public Marshmallow\Validation\Rules\Issn::__construct()
The given value must be a in format of a JSON Web Token.
public Marshmallow\Validation\Rules\Jwt::__construct()
The given value must be formated in Kebab case.
public Marshmallow\Validation\Rules\Kebabcase::__construct()
The given value must be all lower case letters.
public Marshmallow\Validation\Rules\Lowercase::__construct()
The given value must verify against its included Luhn algorithm check digit.
public Marshmallow\Validation\Rules\Luhn::__construct()
Checks for a valid Mime Type (Media type).
public Marshmallow\Validation\Rules\MimeType::__construct()
The field under validation must be a postal code of the given country.
public Marshmallow\Validation\Rules\Postalcode::__construct(array $countrycodes = [])
countrycode
Country code in ISO-639-1 format.
public static Marshmallow\Validation\Rules\Postalcode::countrycode(array $countrycodes): Postalcode
countrycode
Country code in ISO-639-1 format.
public static Marshmallow\Validation\Rules\Postalcode::reference(string $reference): Postalcode
reference
Reference key to get ISO-639-1 country code from other data in validator.
The field under validation must be a valid version numbers using Semantic Versioning.
public Marshmallow\Validation\Rules\SemVer::__construct()
The field under validation must be a user- and SEO-friendly short text.
public Marshmallow\Validation\Rules\Slug::__construct()
The field under validation must formated as Snake case text.
public Marshmallow\Validation\Rules\Snakecase::__construct()
The field under validation must formated in Title case.
public Marshmallow\Validation\Rules\Titlecase::__construct()
The field under validation must be a valid Universally Unique Lexicographically Sortable Identifier.
public Marshmallow\Validation\Rules\Ulid::__construct()
The field under validation must be all upper case.
public Marshmallow\Validation\Rules\Uppercase::__construct()
The field under validation must be a valid username. Consisting of alpha-numeric characters, underscores, minus and starting with a alphabetic character. Multiple underscore and minus chars are not allowed. Underscore and minus chars are not allowed at the beginning or end.
public Marshmallow\Validation\Rules\Username::__construct()
With this package comes a Docker image to build a test suite container. To build this container you have to have Docker installed on your system. You can run all tests with this command.
$ docker-compose run --rm --build tests
Marshmallow Validation is licensed under the MIT License.