Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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
Appearance settings

A set of useful Laravel validation rules

License

NotificationsYou must be signed in to change notification settings

f9webltd/laravel-validation-rules

Repository files navigation

Latest Stable VersionScrutinizer coverage (GitHub/BitBucket)Scrutinizer code quality (GitHub/Bitbucket)Build StatusStyleCI StatusLicense

Useful Laravel Validation Rules

A collection of useful Laravel validation rules.

Requirements

PHP >= 7.2, Laravel>=5.8 | 6.x | 7.x | 8.x.

Installation

composer require f9webltd/laravel-validation-rules

To publish the package validation message translations:

php artisan vendor:publish --provider="F9Web\ValidationRules\ValidationRulesServiceProvider"

Published translations are available atresources/lang/vendor/f9web-validation-rules/messages.php.

Usage

As discussed in the officialLaravel documentation, import the required rule whenever required:

useF9Web\ValidationRules\Rules\TitleCase;// ...$request->validate(['team' => ['required',newTitleCase()],]);

Alternatively use the rule directly with aLaravel form request object

Available rules

Base64EncodedString

Ensure the passed attribute is a valid base 64 encoded string.

Coordinate

Ensure the passed attribute is a valid comma separated Latitude and Longitude string. For example:51.507877,-0.087732.

DomainRestrictedEmail

Ensure the passed email in question is part of the provided whitelist of domains.

For instance, to ensure the given email domain isf9web.co.uk orlaravel.com:

useF9Web\ValidationRules\Rules\DomainRestrictedEmail;// ...$request->validate(['email' => ['required',         (newDomainRestrictedEmail())->validDomains(['f9web.co.uk','laravel.com',        ]),    ],]);

The validation message will include the list of whitelisted domains based upon the provided configuration.

ExcludesHtml

Ensure the passed attribute does not contain HTML.

HexColourCode

Ensure the passed attribute is a valid hex colour code (three of six characters in length), optionally validating the presence of the# prefix.

Minimum usage example to validate a short length code with the prefix i.e.#fff:

useF9Web\ValidationRules\Rules\HexColourCode;(newHexColourCode());

Extended usage example to validate a long length code , omitting prefix i.e.cc0000:

useF9Web\ValidationRules\Rules\HexColourCode;(newHexColourCode())->withoutPrefix()->longFormat();

Honorific

Ensure the passed attribute is a valid honorific, omitting appended dots. The list of valid honorifics is availablehere.

IncludesHtml

Ensure the passed attribute contains HTML.

NoWhitespace

Ensure the passed attribute contains no whitespace.

NumberParity

Validate the number parity.

An odd number:

useF9Web\ValidationRules\Rules\NumberParity;// ...$request->validate(['amount' => ['required',         (newNumberParity())->odd(),    ],]);

An even number:

useF9Web\ValidationRules\Rules\NumberParity;// ...$request->validate(['amount' => ['required',         (newNumberParity())->even(),    ],]);

StringContains

Ensure the given attribute contains the provided strings.

Minimum usage example to ensure the attribute in question contains the stringphp orlaravel:

useF9Web\ValidationRules\Rules\StringContains;// ...$request->validate(['description' => ['required',         (newStringContains())->phrases(['laravel','php',        ]),    ],]);

Optionally force the string to containall provided phrases:

useF9Web\ValidationRules\Rules\StringContains;// ...$request->validate(['description' => ['required',         (newStringContains())->phrases(['laravel','php',        ])->strictly(),    ],]);

The validation message will include the list phrases based upon the provided configuration.

StrongPassword

Ensure the given attribute matches the provided conditions.

Minimum usage example to ensure the attribute:

  • is a minimum of eight characters in length
  • contains upper and lowercase characters
  • contains at least one number
useF9Web\ValidationRules\Rules\StrongPassword;// ...$request->validate(['password' => ['required',         (newStrongPassword()),    ],]);

Additional methods are available.

useF9Web\ValidationRules\Rules\StrongPassword;// ...$request->validate(['password' => ['required',         (newStrongPassword())            ->forceUppercaseCharacters()            ->forceLowercaseCharacters(false)            ->forceNumbers()            ->forceSpecialCharacters()// ->withSpecialCharacters('£$*%^'),    ],]);

The default special characters are!@#$%^&*()\-_=+{};:,<."£~?|>. Optionally thewithSpecialCharacters() method can be used to define a custom list.

TitleCase

Ensure the provided attribute istitle case.

UKMobilePhone

Ensure the provided attribute is a valid UK mobile telephone number.

Uppercase

Ensure the provided attribute is entirely uppercase.

Contribution

Any ideas are welcome. Feel free to submit any issues or pull requests.

Testing

composertest

Security

If you discover any security related issues, please emailrob@f9web.co.uk instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please seeLicense File for more information.

About

A set of useful Laravel validation rules

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp