Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Missing Laravel Validation Rules

License

NotificationsYou must be signed in to change notification settings

Intervention/validation

Repository files navigation

Intervention Validation is an extension library for Laravel's own validationsystem. The package adds rules to validate data like IBAN, BIC, ISBN,creditcard numbers and more.

Latest VersionTestsMonthly DownloadsSupport me on Ko-fi

Installation

You can install this package quick and easy with Composer.

Require the package via Composer:

$ composer require intervention/validation

Laravel integration

The Validation library is built to work with the Laravel Framework (>=10). Itcomes with a service provider, which will be discovered automatically andregisters the validation rules into your installation. The package provides 30additional validation rules including multi language error messages, which canbe used like Laravel's own validation rules.

useIlluminate\Support\Facades\Validator;useIntervention\Validation\Rules\Creditcard;useIntervention\Validation\Rules\Hexadecimalcolor;useIntervention\Validation\Rules\Username;$validator = Validator::make($request->all(), ['color' =>newHexadecimalcolor([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]);

Changing the error messages:

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 likedescribed in the docs.

Available Rules

The following validation rules are available with this package.

Austrian insurance Number (austrian social security number)

The field under validation must be anAustrian insurance number

public Intervention\Validation\Rules\AustrianInsuranceNumber::__construct()

Base64 encoded string

The field under validation must beBase64 encoded.

public Intervention\Validation\Rules\Base64::__construct()

Business Identifier Code (BIC)

Checks for a validBusiness Identifier Code (BIC).

public Intervention\Validation\Rules\Bic::__construct()

Camel case string

The field under validation must be a formatted inCamel case.

public Intervention\Validation\Rules\Camelcase::__construct()

Classless Inter-Domain Routing (CIDR)

Check if the value is aClassless Inter-Domain Routing notation (CIDR).

public Intervention\Validation\Rules\Cidr::__construct()

Creditcard Number

The field under validation must be a validcreditcard number.

public Intervention\Validation\Rules\Creditcard::__construct()

Data URI scheme

The field under validation must be a validData URI.

public Intervention\Validation\Rules\DataUri::__construct(?array $media_types = null)

Domain name

The field under validation must be a well formeddomainname.

public Intervention\Validation\Rules\Domainname::__construct()

European Article Number (EAN)

Checks for a validEuropean Article Number.

public Intervention\Validation\Rules\Ean::__construct(array $lengths = [8, 13])

Parameters

length

Optional integer length (8 or 13) to check only for EAN-8 or EAN-13.

Global Release Identifier (GRid)

The field under validation must be aGlobal Release Identifier.

public Intervention\Validation\Rules\Grid::__construct()

Global Trade Item Number (GTIN)

Checks for a validGlobal Trade Item Number.

public Intervention\Validation\Rules\Gtin::__construct(array $lengths = [8, 12, 13, 14])

Parameters

length

Optional array of allowed lengths to check only for certain types (GTIN-8, GTIN-12, GTIN-13 or GTIN-14).

Hexadecimal color code

The field under validation must be a validhexadecimal color code.

public Intervention\Validation\Rules\Hexadecimalcolor::__construct(array $lengths = [3, 4, 6, 8])

Parameters

length

Optional length as integer to check only for shorthand (3 or 4 characters) or full hexadecimal (6 or 8 characters) form.

HSL Color

The field under validation must be a validHSL color code.

public Intervention\Validation\Rules\Hslcolor::__construct()

HSV Color

The field under validation must be a validHSV/HSB color code.

public Intervention\Validation\Rules\Hsvcolor::__construct()

Text without HTML

The field under validation must be free of any html code.

public Intervention\Validation\Rules\HtmlClean::__construct()

International Bank Account Number (IBAN)

Checks for a validInternational Bank Account Number (IBAN).

public Intervention\Validation\Rules\Iban::__construct()

International Mobile Equipment Identity (IMEI)

The field under validation must be aInternational Mobile Equipment Identity (IMEI).

public Intervention\Validation\Rules\Imei::__construct()

International Standard Book Number (ISBN)

The field under validation must be a validInternational Standard Book Number (ISBN).

public Intervention\Validation\Rules\Isbn::__construct(array $lengths = [10, 13])

Parameters

length

Optional length parameter as integer to check only for ISBN-10 or ISBN-13.

International Securities Identification Number (ISIN)

Checks for a validInternational Securities Identification Number (ISIN).

public Intervention\Validation\Rules\Isin::__construct()

International Standard Serial Number (ISSN)

Checks for a validInternational Standard Serial Number (ISSN).

public Intervention\Validation\Rules\Issn::__construct()

JSON Web Token (JWT)

The given value must be a in format of aJSON Web Token.

public Intervention\Validation\Rules\Jwt::__construct()

Kebab case string

The given value must be formatted inKebab case.

public Intervention\Validation\Rules\Kebabcase::__construct()

Latitude

Checks for a valid geographicLatitude.

public Intervention\Validation\Rules\Latitude::__construct()

Longitude

Checks for a valid geographicLongitude.

public Intervention\Validation\Rules\Longitude::__construct()

LatLng

Checks for a valid geographic comma separated pair of aLatitude and aLongitude.

public Intervention\Validation\Rules\LatLng::__construct()

Lower case string

The given value must be all lower case letters.

public Intervention\Validation\Rules\Lowercase::__construct()

Luhn algorithm

The given value must verify against its includedLuhn algorithm check digit.

public Intervention\Validation\Rules\Luhn::__construct()

Media (MIME) type

Checks for a validMime Type (Media type).

public Intervention\Validation\Rules\MimeType::__construct()

Postal Code

The field under validation must be apostal code of the given country.

public Intervention\Validation\Rules\Postalcode::__construct(array $countrycodes = [])

Parameters

countrycode

Country code inISO-639-1 format.

Postal Code (static instantiation)

public static Intervention\Validation\Rules\Postalcode::countrycode(array $countrycodes): Postalcode

Parameters

countrycode

Country code inISO-639-1 format.

Postal Code (static instantiation with reference)

public static Intervention\Validation\Rules\Postalcode::reference(string $reference): Postalcode

Parameters

reference

Reference key to getISO-639-1 country code from other data in validator.

Semantic Version Number

The field under validation must be a valid version numbers usingSemantic Versioning.

public Intervention\Validation\Rules\SemVer::__construct()

SEO-friendly short text (Slug)

The field under validation must be a user- andSEO-friendly short text.

public Intervention\Validation\Rules\Slug::__construct()

Snake case string

The field under validation must formatted asSnake case text.

public Intervention\Validation\Rules\Snakecase::__construct()

Title case string

The field under validation must formatted inTitle case.

public Intervention\Validation\Rules\Titlecase::__construct()

Universally Unique Lexicographically Sortable Identifier (ULID)

The field under validation must be a validUniversally Unique Lexicographically Sortable Identifier.

public Intervention\Validation\Rules\Ulid::__construct()

Upper case string

The field under validation must be all upper case.

public Intervention\Validation\Rules\Uppercase::__construct()

Username

The field under validation must be a valid username. Consisting ofalpha-numeric characters, underscores, minus and starting with a alphabeticcharacter. Multiple underscore and minus chars are not allowed. Underscore andminus chars are not allowed at the beginning or end.

public Intervention\Validation\Rules\Username::__construct()

Development & Testing

With this package comes a Docker image to build a test suite container. Tobuild this container you have to have Docker installed on your system. You canrun all tests with this command.

$ docker-compose run --rm --build tests

Authors

This library is developed and maintained byOliver Vogel

Thanks to the community ofcontributors who have helped to improve this project.

License

Intervention Validation is licensed under theMIT License.


[8]ページ先頭

©2009-2025 Movatter.jp