Reprint: [TP5.0] TP5 Validate validation rules

Here are some built tp5 validation rules:

Format Validation categories:

'name'=>'require'

Verify a field value is a number (using filter_varverification), for example:

number or integer
'name'=>'number'

Verify whether the value of a field floating point numbers (use filter_varauthentication), for example:

float
'name'=>'float'
 

Verify whether the value of a field as a boolean value (using filter_varverification), for example:

  boolean
'boolean'=>'boolean'

Verify whether the value of a field email address (using filter_varverification), for example:

    email
'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 strtotimejudge 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_varverification), for example:

url
'url'=>'url'

Verify a field value is a valid IP address (using filter_varverification), 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:

Copy the code
    length:num1,num2
'name'=>'length:4,25'

  Or a specified length

'name'=>'length:4'
Copy the code

Verify maximum length of a field, for example:

 

Copy the code
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.

Copy the code

 

Verification of the minimum length of a field value, for example:

 

Copy the code
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.

Copy the code

 

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:

 

Copy the code
    egt or> =
'score' => 'EGT: 60 || 
'num' => '> = 100'

 

Copy the code

 

Verify is greater than a certain value, for example:

 

Copy the code
    Alternatively gt>
'score'=>'gt:60' ||
'num'=>'>:100'

 

Copy the code

 

Verify less than or equal to a value, for example:

 

Copy the code
    elt or <=
'score'=>'elt:100' ||
'num'=>'<=:100'

 

Copy the code

 

Verify less than a certain value, for example:

 

Copy the code
    Alternatively lt <
'score'=>'lt:100'||
'num'=>'<:100'

 

Copy the code

 

Verify equal to a certain value, for example:

 

Copy the code
    or same or = eq
'score'=>'eq:100'||
'num'=>'=:100'||
'num'=>'same:100'

 

Copy the code

 

filter verification

Supports filter_var be verified, such as:

 

'ip'=>'filter:validate_ip'

 

Regular verification

Support the direct use of regular verification, such as:

Copy the code
'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'],

 

Copy the code

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:

Copy the code
    unique:table,field,except,pk
Copy the code
// 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. '],
Copy the code
Copy the code

  Verify value of a field must be equal to a certain time, for example:

Copy the code
    requireIf:field,value
// the value when the account password must equal 1 
  'password' => 'requireIf: account, 1'

 

Copy the code

  Verify the value of a field when there must be, for example:

Copy the code
    requireWith:field
 // When the account password field must have a value of 
  'password' => 'requireWith: account'

 

Copy the code

 

Here are some built tp5 validation rules:

Guess you like

Origin www.cnblogs.com/xuzhengzong/p/11614772.html