Here are some built tp5 validation rules:
Format Validation categories:
'name'=>'require'
Verify a field value is a number (using filter_var
verification), for example:
number or integer
'name'=>'number'
Verify whether the value of a field floating point numbers (use filter_var
authentication), for example:
float
'name'=>'float'
Verify whether the value of a field as a boolean value (using filter_var
verification), for example:
boolean
'boolean'=>'boolean'
Verify whether the value of a field email address (using filter_var
verification), for example:
'email'=>'email'
Verify value of a field is an array, for example:
array
'info'=>'array'
Verify whether a field is yes, on, or 1. This is useful when confirming "Terms of Service" agree, for example:
accepted
'accept'=>'accepted'
Verification value is a valid date, for example:
Date values will be: Note strtotime
judge later.
date
'date'=>'date'
Verify the value of a field is a letter, for example:
alpha
'name'=>'alpha'
Verify whether the value of a field as letters and numbers, such as:
alphaNum
'name'=>'alphaNum'
Verify whether the value of a field of letters and numbers, underscores _
and dashes -
, for example:
alphaDash
'name'=>'alphaDash'
Verify the value of a field is a valid domain name or IP, for example:
activeUrl
'host'=>'activeUrl'
Verify whether the value of a field URL address valid (using filter_var
verification), for example:
url
'url'=>'url'
Verify a field value is a valid IP address (using filter_var
verification), for example:
Note: Support verify the IP address ipv4 and ipv6 format.
ip
'ip'=>'ip'
Verify whether the value of a field to specify the date format, for example:
dateFormat:format
'create_time'=>'dateFormat:y-m-d'
The length and type verification section
in
"Were the '=>' In: 1,2,3 '
Verification value is not a field in a range of, for example:
notIn
"Were the '=>' notino: 1,2,3 '
Verify whether the value of a field in a certain range, for example:
between
'num'=>'between:1,10'
Verification value is not a field in a range of, for example:
notBetween
'num'=>'notBetween:1,10'
Verify a field length value is in a range of, for example:
length:num1,num2
'name'=>'length:4,25'
Or a specified length
'name'=>'length:4'
Verify maximum length of a field, for example:
max:number
'name'=>'max:25'
If the authentication data is an array, the length of the array is determined.
If the data is verified File object, size of the file is determined.
Verification of the minimum length of a field value, for example:
min:number
'name'=>'min:5'
If the authentication data is an array, the length of the array is determined.
If the data is verified File object, size of the file is determined.
Verify whether the value of a field after a certain date, such as:
after: Date
'begin_time' =>'after:2016-3-18',
Verify whether the value of a field before a certain date, such as:
before: Date
'end_time' =>'before:2016-10-01',
Verify the current operation (note not a value) is within a valid date, for example:
expire: start time, end time
'expire_time' =>'expire:2016-2-1,2016-10-01',
Verify whether the current request IP in a range, for example:
allowIp:allow1,allow2,...
'name' =>'allowIp:114.45.4.55',
Note: This rule can be used to access a background
Verify whether the current request IP block access to, for example:
denyIp:allow1,allow2,...
'name' =>'denyIp:114.45.4.55',
Comparison of class field
Verify that the value of a field and another field of the same
confirm
'repassport'=>'require|confirm:passport'
Verify that the value of a field and another field inconsistent
different
'name'=>'require|different:account'
Verify greater than or equal to a value, for example:
egt or> =
'score' => 'EGT: 60 || 'num' => '> = 100'
Verify is greater than a certain value, for example:
Alternatively gt>
'score'=>'gt:60' || 'num'=>'>:100'
Verify less than or equal to a value, for example:
elt or <=
'score'=>'elt:100' || 'num'=>'<=:100'
Verify less than a certain value, for example:
Alternatively lt <
'score'=>'lt:100'|| 'num'=>'<:100'
Verify equal to a certain value, for example:
or same or = eq
'score'=>'eq:100'|| 'num'=>'=:100'|| 'num'=>'same:100'
filter verification
Supports filter_var be verified, such as:
'ip'=>'filter:validate_ip'
Regular verification
Support the direct use of regular verification, such as:
'zip' => '\ d {6}' or 'zip' => 'regex: \ d {6}',
If your regular expression contains |
symbols, you must use an array define.
'accepted'=>['regex'=>'/^(yes|on|1)$/i'],
Upload verification
Verify is an upload file
file
Verify is an image file, width and height are optional type, width and height must be defined at the same time.
image:width,height,type
Verify upload the file suffix
fileExt: Allowed file suffix
Verify upload type
fileMime: Allowed file types
Verify upload file size
fileSize: Allowed file size in bytes
Behavior verification
Use behavior verification data, such as:
'data'=>'behavior:\app\index\behavior\Check'
Other verification
Verify whether the current request is the only field value, for example:
unique:table,field,except,pk
// represents verify whether the value of the name field in the user table (not including prefix) only
'name' => 'UNIQUE: user',
// verify other fields
'name' => 'UNIQUE: user, Account',
// excluding a primary key
'name' => 'UNIQUE: User, Account, 10',
// specifies a primary key negative
'name' => 'unique: user, account, 10, user_id',
If you need to verify the only complex conditions, you can use the following ways:
// verify condition plurality of unique field validation 'name' => 'UNIQUE: User, Account Status ^', // complex validation criteria 'name' => 'unique: user, status = 1 & account =' $ data [ 'account. '],
Verify value of a field must be equal to a certain time, for example:
requireIf:field,value
// the value when the account password must equal 1 'password' => 'requireIf: account, 1'
Verify the value of a field when there must be, for example:
requireWith:field
// When the account password field must have a value of 'password' => 'requireWith: account'
Here are some built tp5 validation rules: