KwesForms V2 is finally here and it's game changing! Try it now.
Home How it Works Components Validation Spam Cloud Emails Data Security Pricing Docs API Docs FAQ Sign In Try It Free

Form Validation Rules Free & Bronze Plan


accepted

The field under validation must be yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance.

<div class="kw-checkbox-group" rules="accepted">
      <input type="checkbox" name="terms" value="true" label="I accept the terms and conditions">
</div>

after_or_equal:date

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

<input type="datepicker" name="date" rules="after_or_equal:June 06, 2019">

alpha

The field under validation must be entirely alphabetic characters.

<input type="text" name="username" rules="alpha">

alpha_dash

The field under validation may have alpha-numeric characters, dashes and underscores.

<input type="text" name="username" rules="alpha_dash">

alpha_num

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

<input type="text" name="password" rules="alpha_num">

array

The field under validation must be an array.




<div class="kw-checkbox-group" rules="array">
      <input type="checkbox" name="fruits" value="Apple" label="Apple">
      <input type="checkbox" name="fruits" value="Orange" label="Orange">
      <input type="checkbox" name="fruits" value="Kiwi" label="Kiwi">
</div>


bail

Stop running validation rules after the first validation failure.

<input type="text" name="number" rules="bail|required|numeric">

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.

<input type="datepicker" name="date" rules="before:June 06, 2019">

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, make sure to add the rule numeric like we did below. That way it is not checked as a string.

<input type="number" name="number" rules="between:5,10|numeric">

boolean

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


<div class="kw-radio-group" rules="boolean">
      <input type="radio" name="boolean" value="1" label="True">
      <input type="radio" name="boolean" value="0" label="False">
</div>

confirmed

The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.

<input type="password" name="password" rules="required|confirmed">
<input type="password" name="password_confirmation" rules="required">

date

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

<input type="datepicker" name="date" rules="date">

different:field

The field under validation must have a different value than field. In this example Second Field mus be different than First Field.

<select name="firstField" rules="required">
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
</select>

<select name="secondField" rules="required|different:firstField">
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
</select>

digits:value

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

<input type="number" name="digitNumber" rules="digits:4">

digits_between:min,max

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

<input type="number" name="digitNumber" rules="digits_between:2,5">

email

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

<input type="email" name="email" rules="email">

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.

<input type="file" name="upload" rules="image">

filled

The field under validation must not be empty when it is present.

<input type="text" name="country" rules="filled">

gt:field

The field under validation must be greater than the given field. The two fields must be of the same type. Strings, numerics, arrays, and files are evaluated using the same conventions as the size rule.

<input type="text" name="minspeed">
<input type="text" name="maxspeed" rules="gt:minspeed">

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. Strings, numerics, arrays, and files are evaluated using the same conventions as the size rule.

<input type="text" name="minspeed">
<input type="text" name="maxspeed" rules="gte:minspeed">

image

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

<input type="file" name="upload" rules="image">

in_array:anotherfield.*

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


integer

The field under validation must be an integer.

<input type="text" name="integer" rules="integer">

IP

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

<input type="text" name="ip" rules="ip">

IPv4

The field under validation must be an IPv4 address.

<input type="text" name="ipv4" rules="ipv4">

IPv6

The field under validation must be an IPv6 address.

<input type="text" name="ipv6" rules="ipv6">

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. Strings, numerics, arrays, and files are evaluated using the same conventions as the size rule.

<input type="text" name="firstfield">
<input type="text" name="secondfield" rules="lt:firstfield">

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. Strings, numerics, arrays, and files are evaluated using the same conventions as the size rule.

<input type="text" name="firstfield">
<input type="text" name="secondfield" rules="lte:firstfield">

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.
<input type="text" name="name" rules="max:5">
<input type="file" name="upload" rules="max:1000">

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

<input type="file" name="upload" rules="mimetypes:text/plain,text/rtf">

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

This example only accepts .pdf files.

<input type="file" name="upload" rules="mimes:pdf">

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.
<input type="text" name="name" rules="min:3">
<input type="file" name="upload" rules="min:1000">

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"

Note: 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.

<input type="text" name="age" rules="numeric">

numeric

The field under validation must be numeric.

<input type="text" name="age" rules="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"

Note: 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.
<input type="text" name="name" rules="required">

required_if:anotherfield,value,...

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

<div class="kw-radio-group">
<input type="radio" name="are_you_married" value="yes" label="Yes">
<input type="radio" name="are_you_married" value="no" label="No">
</div>

<input type="text" name="name_of_spouse" rules="required_if:are_you_married,yes">

required_unless:anotherfield,value,...

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

<select name="firstField" rules="required">
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
</select>

<select name="secondField" rules="required|different:firstField">
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
</select>

required_with:foo,bar,...

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

<input type="text" name="country">
<input type="text" name="state">
<input type="text" name="city" rules="required_with:country,state">

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.

<input type="text" name="country">
<input type="text" name="state">
<input type="text" name="city" rules="required_with_all:country,state">

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.

<input type="text" name="home_number">
<input type="text" name="mobile_number" rules="required_without:home_number">

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.

<input type="text" name="home_number">
<input type="text" name="mobile_number">
<input type="text" name="email" rules="required_without_all:home_number,mobile">

same:field

The given field must match the field under validation.

<input type="text" name="phone" rules="required">
<input type="text" name="phone2" rules="required|same:phone">

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.
<input type="file" name="upload" rules="size:100">
<input type="text" name="size" rules="size:5">

starts_with:foo,bar,...

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

<input type="text" name="id" rules="starts_with:SAFC">

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.

<input type="text" name="url" rules="url">

uuid

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

<input type="text" name="uuid" rules="uuid">