|
| 1 | +## Available Rules |
| 2 | + |
| 3 | +Validation rules do not have an implicit 'required'. If a field is _undefined_ or an empty string, it will pass validation. If you want a validation to fail for undefined or '', use the _required_ rule. |
| 4 | + |
| 5 | +#### accepted |
| 6 | + |
| 7 | +The field under validation must be yes, on, 1 or true. This is useful for validating "Terms of Service" acceptance. |
| 8 | + |
| 9 | +#### after:date |
| 10 | + |
| 11 | +The field under validation must be after the given date. |
| 12 | + |
| 13 | +#### after_or_equal:date |
| 14 | + |
| 15 | +The field unter validation must be after or equal to the given field |
| 16 | + |
| 17 | +#### alpha |
| 18 | + |
| 19 | +The field under validation must be entirely alphabetic characters. |
| 20 | + |
| 21 | +#### alpha_dash |
| 22 | + |
| 23 | +The field under validation may have alpha-numeric characters, as well as dashes and underscores. |
| 24 | + |
| 25 | +#### alpha_num |
| 26 | + |
| 27 | +The field under validation must be entirely alpha-numeric characters. |
| 28 | + |
| 29 | +#### array |
| 30 | + |
| 31 | +The field under validation must be an array. |
| 32 | + |
| 33 | +#### before:date |
| 34 | + |
| 35 | +The field under validation must be before the given date. |
| 36 | + |
| 37 | +#### before_or_equal:date |
| 38 | + |
| 39 | +The field under validation must be before or equal to the given date. |
| 40 | + |
| 41 | +#### between:min,max |
| 42 | + |
| 43 | +The field under validation must have a size between the given min and max. Strings, numerics, and files are evaluated in the same fashion as the size rule. |
| 44 | + |
| 45 | +#### boolean |
| 46 | + |
| 47 | +The field under validation must be a boolean value of the form `true`, `false`, `0`, `1`, `'true'`, `'false'`, `'0'`, `'1'`, |
| 48 | + |
| 49 | +#### confirmed |
| 50 | + |
| 51 | +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. |
| 52 | + |
| 53 | +#### date |
| 54 | + |
| 55 | +The field under validation must be a valid date format which is acceptable by Javascript's `Date` object. |
| 56 | + |
| 57 | +#### digits:value |
| 58 | + |
| 59 | +The field under validation must be numeric and must have an exact length of value. |
| 60 | + |
| 61 | +#### digits_between:min,max |
| 62 | + |
| 63 | +The field under validation must be numeric and must have length between given min and max. |
| 64 | + |
| 65 | +#### different:attribute |
| 66 | + |
| 67 | +The given field must be different than the field under validation. |
| 68 | + |
| 69 | +#### email |
| 70 | + |
| 71 | +The field under validation must be formatted as an e-mail address. |
| 72 | + |
| 73 | +#### hex |
| 74 | + |
| 75 | +The field under validation should be a hexadecimal format. Useful in combination with other rules, like `hex|size:6` for hex color code validation. |
| 76 | + |
| 77 | +#### in:foo,bar,... |
| 78 | + |
| 79 | +The field under validation must be included in the given list of values. The field can be an array or string. |
| 80 | + |
| 81 | +#### integer |
| 82 | + |
| 83 | +The field under validation must have an integer value. |
| 84 | + |
| 85 | +#### max:value |
| 86 | + |
| 87 | +Validate that an attribute is no greater than a given size |
| 88 | + |
| 89 | +_Note: Maximum checks are inclusive._ |
| 90 | + |
| 91 | +#### min:value |
| 92 | + |
| 93 | +Validate that an attribute is at least a given size. |
| 94 | + |
| 95 | +_Note: Minimum checks are inclusive._ |
| 96 | + |
| 97 | +#### not_in:foo,bar,... |
| 98 | + |
| 99 | +The field under validation must not be included in the given list of values. |
| 100 | + |
| 101 | +#### numeric |
| 102 | + |
| 103 | +Validate that an attribute is numeric. The string representation of a number will pass. |
| 104 | + |
| 105 | +#### present |
| 106 | + |
| 107 | +The field under validation must be present in the input data but can be empty. |
| 108 | + |
| 109 | +#### required |
| 110 | + |
| 111 | +Checks if the length of the String representation of the value is > |
| 112 | + |
| 113 | +#### required_if:anotherfield,value |
| 114 | + |
| 115 | +The field under validation must be present and not empty if the anotherfield field is equal to any value. |
| 116 | + |
| 117 | +#### required_unless:anotherfield,value |
| 118 | + |
| 119 | +The field under validation must be present and not empty unless the anotherfield field is equal to any value. |
| 120 | + |
| 121 | +#### required_with:foo,bar,... |
| 122 | + |
| 123 | +The field under validation must be present and not empty only if any of the other specified fields are present. |
| 124 | + |
| 125 | +#### required_with_all:foo,bar,... |
| 126 | + |
| 127 | +The field under validation must be present and not empty only if all of the other specified fields are present. |
| 128 | + |
| 129 | +#### required_without:foo,bar,... |
| 130 | + |
| 131 | +The field under validation must be present and not empty only when any of the other specified fields are not present. |
| 132 | + |
| 133 | +#### required_without_all:foo,bar,... |
| 134 | + |
| 135 | +The field under validation must be present and not empty only when all of the other specified fields are not present. |
| 136 | + |
| 137 | +#### same:attribute |
| 138 | + |
| 139 | +The given field must match the field under validation. |
| 140 | + |
| 141 | +#### size:value |
| 142 | + |
| 143 | +The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. |
| 144 | + |
| 145 | +#### string |
| 146 | + |
| 147 | +The field under validation must be a string. |
| 148 | + |
| 149 | +#### url |
| 150 | + |
| 151 | +Validate that an attribute has a valid URL format |
| 152 | + |
| 153 | +#### regex:pattern |
| 154 | + |
| 155 | +The field under validation must match the given regular expression. |
| 156 | + |
| 157 | +**Note**: When using the ``regex`` pattern, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character. |
| 158 | +For each backward slash that you used in your regex pattern, you must escape each one with another backward slash. |
| 159 | + |
| 160 | +#### Example 3 - Regex validation |
| 161 | + |
| 162 | +```js |
| 163 | + |
| 164 | +forms.useRules({ |
| 165 | + name: 'required|size:3', |
| 166 | + salary: ['required', 'regex:/^(?!0\\.00)\\d{1,3}(,\\d{3})*(\\.\\d\\d)?$/'], |
| 167 | + yearOfBirth: ['required', 'regex:/^(19|20)[\\d]{2,2}$/'] |
| 168 | +}) |
| 169 | +``` |
| 170 | + |
| 171 | +The valid data will be like, |
| 172 | + |
| 173 | +```js |
| 174 | + |
| 175 | +{ |
| 176 | + name: 'Doe', |
| 177 | + salary: '10,000.00', |
| 178 | + yearOfBirth: '1980' |
| 179 | +} |
| 180 | +``` |
| 181 | + |
| 182 | +#### Example 4 - Type Checking Validation |
| 183 | + |
| 184 | +```js |
| 185 | + |
| 186 | +form.useRules({ |
| 187 | + age: ['required', { 'in': [29, 30] }], |
| 188 | + name: [{ required_if: ['age', 30] }] |
| 189 | +}); |
| 190 | + |
| 191 | +``` |
| 192 | + |
| 193 | +The valid data will be like, |
| 194 | + |
| 195 | +```js |
| 196 | +{ |
| 197 | + age: 30, |
| 198 | + name: '' |
| 199 | +} |
| 200 | +``` |
0 commit comments