在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Intervention/validation开源软件地址(OpenSource Url):https://github.com/Intervention/validation开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Intervention ValidationIntervention 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. InstallationYou can install this package quick and easy with Composer. Require the package via Composer:
Laravel integrationThe Validation library is built to work with the Laravel Framework (>=7). 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 error messages, which can be used like Laravel's own validation rules. use Illuminate\Support\Facades\Validator;
use Intervention\Validation\Rules\Creditcard;
use Intervention\Validation\Rules\HexColor;
use Intervention\Validation\Rules\Username;
$validator = Validator::make($request->all(), [
'color' => new Hexcolor(3), // 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 // example
'iban' => 'Please enter IBAN number!', Or add your custom messages directly to the validator like described in the docs. Standalone usageIt is also possible to use this library without the Laravel framework. You won't have the Laravel facades available, so make sure to use use Intervention\Validation\Validator;
use Intervention\Validation\Rules\Creditcard;
use Intervention\Validation\Exceptions\ValidationException;
// use static factory method to create laravel validator
$validator = Validator::make($request->all(), [
'ccnumber' => new Creditcard(),
'iban' => ['required', 'iban'],
'color' => 'required|hexcolor:3',
]);
// validate single values by calling static methods
$result = Validator::isHexcolor('foobar'); // false
$result = Validator::isHexcolor('#ccc'); // true
$result = Validator::isBic('foo'); // false
// assert single values
try {
Validator::assertHexcolor('foobar');
} catch (ValidationException $e) {
$message = $e->getMessage();
} Available RulesThe following validation rules are available with this package. Base64 encoded stringThe field under validation must be Base64 encoded.
Business Identifier Code (BIC)Checks for a valid Business Identifier Code (BIC).
Camel case stringThe field under validation must be a formated in Camel case.
Classless Inter-Domain Routing (CIDR)Check if the value is a Classless Inter-Domain Routing notation (CIDR).
Creditcard NumberThe field under validation must be a valid creditcard number.
Data URI schemeThe field under validation must be a valid Data URI.
Domain nameThe field under validation must be a well formed domainname.
European Article Number (EAN)Checks for a valid European Article Number.
Parameterslength Optional integer length (8 or 13) to check only for EAN-8 or EAN-13. Global Trade Item Number (GTIN)Checks for a valid Global Trade Item Number.
Parameterslength Optional integer length to check only for certain types (GTIN-8, GTIN-12, GTIN-13 or GTIN-14). Hexadecimal color codeThe field under validation must be a valid hexadecimal color code.
Parameterslength Optional length as integer to check only for shorthand (3 characters) or full hexadecimal (6 characters) form. Text without HTMLThe field under validation must be free of any html code.
International Bank Account Number (IBAN)Checks for a valid International Bank Account Number (IBAN).
International Mobile Equipment Identity (IMEI)The field under validation must be a International Mobile Equipment Identity (IMEI).
International Standard Book Number (ISBN)The field under validation must be a valid International Standard Book Number (ISBN).
Parameterslength Optional length parameter as integer to check only for ISBN-10 or ISBN-13. International Securities Identification Number (ISIN)Checks for a valid International Securities Identification Number (ISIN).
International Standard Serial Number (ISSN)Checks for a valid International Standard Serial Number (ISSN).
JSON Web Token (JWT)The given value must be a in format of a JSON Web Token.
Kebab case stringThe given value must be formated in Kebab case.
Lower case stringThe given value must be all lower case letters.
Luhn algorithmThe given value must verify against its included Luhn algorithm check digit.
Media (MIME) typeChecks for a valid Mime Type (Media type).
Postal CodeThe field under validation must be a postal code of the given country.
Parameterscountrycode Country code in ISO-639-1 format. Postal Code (static instantiation)
Parameterscountrycode Country code in ISO-639-1 format. Postal Code (static instantiation with callback)
Parameterscallback Callback to resolve ISO-639-1 country code from other source. Postal Code (static instantiation with reference)
Parametersreference Reference key to get ISO-639-1 country code from other data in validator. Semantic Version NumberThe field under validation must be a valid version numbers using Semantic Versioning.
SEO-friendly short text (Slug)The field under validation must be a user- and SEO-friendly short text.
Snake case stringThe field under validation must formated as Snake case text.
Title case stringThe field under validation must formated in Title case.
Universally Unique Lexicographically Sortable Identifier (ULID)The field under validation must be a valid Universally Unique Lexicographically Sortable Identifier.
Upper case stringThe field under validation must be all upper case.
UsernameThe 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.
LicenseIntervention Validation is licensed under the MIT License. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论