40 Additional Laravel Validation Rules

Laravel Validation system has 60+ validation rules available, but what if you want something extra? You can easily create your own validation rule, or use something already available on the internet. Let's take a look.

22 Rules from Alphametric

First, we start with a series of articles by Matt Kingshott, senior developer at Alphametric, he wrote quite a few posts on Medium and added all the rules into a Github repository. Here's the list of rules available there:

  • StrongPassword: checks for "strong" password
  • TelephoneNumber: valid telephone number
  • RecordOwner: Requires the authenticated user's id to match the user_id column on a given database record e.g. owner:posts,id
  • MonetaryFigure: monetary figure e.g $72.33
  • DisposableEmail: email address which is not disposable
  • DoesNotExist: value is not present in a given database table / column
  • Decimal: decimal with an appropriate format
  • EncodedImage: value is a base64-encoded image of a given mime type
  • LocationCoordinates: comma-separated set of latitude and longitude coordinates
  • FileExists: value is a path to an existing file
  • Equals: value is equal to another given value
  • MacAddress: value is a valid MAC address
  • ISBN: value is a valid ISBN-10 or ISBN-13 number
  • EndsWith: value ends with a given string
  • EvenNumber: value is an even number (decimals are first converted using intval)
  • OddNumber: value is an odd number (decimals are first converted using intval)
  • Lowercase: value is a lowercase string
  • Uppercase: value is a uppercase string
  • Titlecase: value is a titlecase string
  • Domain: value is a domain e.g. google.com, www.google.com
  • CitizenIdentification: value id a citizen identification number of USA, UK or France
  • WithoutWhitespace: value does not include any whitespace characters

8 Rules from Scott Robinson

Another good set of rules is made by Scott Robinson, who created a special website laravel-validation-rules.github.io. It has these rules:

  • Colour: Validates colours, currently supporting hex codes only.
  • Country Codes: Validates 2 & 3 character country codes.
  • Credit Card: This rule will validate that a given credit card number, expiration date or cvc is valid.
  • IP: Validates an ip address is either public or private. Supports ipv4 & ipv6.
  • Phone: Validates phone number format.
  • Subdomain: Validates a user submitted subdomain in your application.
  • Timezone: This rule will validate that a given timezone is valid within the systems datetime database.
  • US State: Validate US States and Canada Provinces.

5 Rules from Spatie

Our beloved Spatie team also have their own repository with a few rules:

  • Authorized: user is authorized to perform an ability on an instance of the given model.
  • CountryCode: field is a valid ISO3166 country code.
  • Enum: value is part of the given enum class, like myclabs/php-enum.
  • ModelsExist: all of the values in the input array exist as attributes for the given model class.
  • Delimited: string contains delimited values, like 'sebastian@example.com, alex@example.com'

5 Rules from Pineco.de

Finally, Gergő D. Nagy from Pineco.de has published an article in late 2017, with a set of validation rules and a repository. It has not been updated since then, so use with caution. Rules are:

  • Checking the user’s password
  • Odd or even numbers
  • Value can be incremented only
  • Value contains specific words
  • Day must be a weekday

Anything I've missed?

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 88 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses