Form Validation Rules

Below are 49 form validation rules and code examples to help you implement them into your form.

List of Validation Rules

Validation Examples

accepted

The field under validation must be true.

after_or_equal:date

The field under validation must be a value after or equal to the given date.

alpha

The field under validation must be entirely alphabetic characters (only letters).

alpha_dash

The field under validation may have alpha, numeric, dash and underscore characters.

alpha_num

The field under validation must be entirely alpha-numeric characters.

array

The field under validation must be an array.

bail

Stop running validation rules after the first validation failure.

before:date

The field under validation must be a value preceding the given date. Like the "after" rule, the name of another field under validation may be supplied as the value of date.

between:min,max

The field under validation must have a size between the given min and max.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.
If the field under validation is numeric, also add the rule "numeric". This way it's not checked as a string.
File upload example

boolean

The field under validation must be able to be cast as a boolean. Accepted input are true, false, 1, 0, "1", and "0".

confirmed

The field under validation must have a matching field with a name of foo_confirmation. For example, if the field under validation is email, a matching email_confirmation field must be present in the input.

date

The field under validation must be a valid, non-relative date.

different:field

The field under validation must have a different value than field. In this example "lunch" must be different than "dinner".

digits:value

The field under validation must be numeric and must have an exact length of value.

digits_between:min,max

The field under validation must have a length between the given min and max.

email

The field under validation must be formatted as an e-mail address.

file

The field under validation must be a successfully uploaded file.

This rule validates against these common file types: jpg, jpeg, gif, png, bmp, tif, psd, pdf, doc, docx, xls, xlsx, txt, mp3, mp4, aac, wav, au, wmv, avi, mpg, mpeg, zip, gz, rar, z, tgz, tar, sitx.

gt:field

The field under validation must be greater than the given field. The two fields must be of the same type.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.

gte:field

The field under validation must be greater than or equal to the given field. The two fields must be of the same type.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.

image

The file under validation must be an image (jpeg, png, bmp, gif, or svg)

in_array:anotherfield.*

The field under validation must exist in anotherfield's values.

integer

The field under validation must be an integer.

ip

The field under validation must be an IP address. This rule accepts ipv4 and ipv6.

ipv4

The field under validation must be an IPv4 address.

ipv6

The field under validation must be an IPv6 address.

json

The field under validation must be a valid JSON string.

lt:field

The field under validation must be less than the given field. The two fields must be of the same type.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.

lte:field

The field under validation must be less than or equal to the given field. The two fields must be of the same type.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.

max:value

The field under validation must be less than or equal to a maximum value.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.
Numeric example
File upload example

mimetypes:text/plain

The file under validation must match one of the given MIME types.

A full listing of MIME types and their corresponding extensions can be seen here: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

mimes:foo,bar

The file under validation must have a specified extension. More than one extension can be specified separated by commas.

A full listing of MIME types and their corresponding extensions can be seen here: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

min:value

The field under validation must have a minimum value.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.
Numeric example
File upload example

not_regex:pattern

The field under validation must not match the given regular expression.

Internally, this rule uses the PHP preg_match function. The pattern specified should obey the same formatting required by preg_match and thus also include valid delimiters. For example: rules="not_regex:/^.+$/i"

When using the regex / not_regex patterns, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.

nullable

The field under validation may be null. This is particularly useful when validating primitive such as strings and integers that can contain null values.

numeric

The field under validation must be numeric.

regex:pattern

The field under validation must match the given regular expression.

Internally, this rule uses the PHP preg_match function. The pattern specified should obey the same formatting required by preg_match and thus also include valid delimiters. For example: rules="regex:/^.+@.+$/i".

When using the regex / not_regex patterns, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.

required

The field under validation must be present in the input data and not empty. A field is considered "empty" if one of the following conditions are true:

  • The value is null.
  • The value is an empty string.
  • The value is an empty array or empty Countable object.
  • The value is an uploaded file with no path.

required_if:anotherfield,value,...

The field under validation must be present and not empty if the anotherfield field is equal to any value.

required_unless:anotherfield,value,...

The field under validation must be present and not empty unless the anotherfield field is equal to any value.

required_with:foo,bar,...

The field under validation must be present and not empty only if any of the other specified fields are present.

required_with_all:foo,bar,...

The field under validation must be present and not empty only if all of the other specified fields are present.

required_without:foo,bar,...

The field under validation must be present and not empty only when any of the other specified fields are not present.

required_without_all:foo,bar,...

The field under validation must be present and not empty only when all of the other specified fields are not present.

same:field

The given field must match the field under validation.

size:value

The field under validation must have a size exactly matching the given value.

  • For string data, value is the number of characters.
  • For numeric data, value is a given integer value.
  • For an array, value is the count of the array.
  • For files, value is the file size in kilobytes.
Numeric example
File upload example

starts_with:foo,bar,...

The field under validation must start with one of the given values.

string

The field under validation must be a string. If you would like to allow the field to also be null, you should assign the nullable rule to the field.

timezone

The field under validation must be a valid timezone identifier according to the timezone_identifiers_list PHP function.

url

The field under validation must be a valid URL.

uuid

The field under validation must be a valid RFC 4122 (version 1, 3, 4, or 5) universally unique identifier (UUID).

Notice anything wrong in our docs? Let us know.