Validation Libraries



( ZN >= 1.0.0 )

The primary purpose of these libraries is to provide data and system security. 

the Validation Used to check the values ​​from form objects.
Validator Used to make data checks.
Validate It is used to do a data filtering.

 

 

# Validation ( ZN >= 0.0.1 )


It was created to provide control of the data sent by forms such as post , get .

 

 

# Application


# Standard Validation Usage
# Form Validation Usage

 

 

# Methods


this validate ( String ... $ args )
this secure ( String ... $ args )
this compare ( Int $ min , Int $ max )
this oldPassword ( String $ password )
this matchPassword ( String $ password )
this match ( String $ data )
this phone ( String $ pattern )
this pattern ( String $ pattern , String $ extra = NULL )
this between ( Float $ min , Float $ max )
this value ( String $ name )
this method ( String $ method )
void rules ( String $ name , Array $ config = [] , String $ viewName = NULL )
Mixed error ( String $ name = 'array' )
Mixed postBack ( String $ name , String $ met = 'post' )
Bool check ( String $ submit = NULL )

 

 

# Validate ( ZN >= 3.0.0 )


Verification method. 

Parameter
String $ Args ... Filters.
identity Identification number check.
e-mail Email checking.
URLs URL address control.
specialch is Special character control.
numeric Number control of data
alpha Control of letters.
My forehead Letters and number control.
phone Phone control.
required Control of empty data that can not be passed.
trim Empty character control.
captcha Security code control. 
return this
Use of
Validation::validate('numeric', 'trim')->rules('phone');

 

 

# Secure ( ZN> = 3.0.0 )


It's a security measure. 

Parameter
String $ Args ... Filters.
Article Control of bad data.
html Control of data with html code content.
xSS Check quotation marks and script.
injection Database injection control.
php Controlling PHP tags.
the script Control of script tags
return this
Use of
Validation::secure('xss', 'html', 'script')->rules('content');

 

 

# Compare ( ZN >= 3.0.0 )


It is the method of comparison. 

Parameter
Int Min $ Minimum character count control.
Int $ max Maximum number of characters control.
return this
Use of
Validation::compare(4, 16)->rules('password');

 

 

# OldPassword ( ZN >= 3.0.0 )


It is the old password control method. 

Parameter
String $ password The name value of the old password input object.
return this
Use of
Validation::oldPassword('oldpass')->rules('newpass');

 

 

# MatchPassword ( ZN >= 3.0.0 )


It is the method that checks whether the password and password repetition match or not in the registration or update processes.

Parameter
String $ password The password is the name value of the input object again.
return this
Use of
Validation::matchPassword('passagain')->rules('pass');

 

 

# Match ( ZN> = 3.0.0 )


It is the method that checks whether two pieces of information match or not.

Parameter
String $ data The name value of the input object to be controlled.
return this
Use of
Validation::match('oldpass')->rules('newpass');

 

 

# Phone ( ZN> = 3.0.0 )


It is the method that makes telephone information control.

Parameter
String $ pattern Pattern. The pattern to be displayed with each digit * is used.
return this
Use of
Validation::phone('( *)-( *)-( )-( )')->rules('example');

Any data that conforms to the above rule must be in a sequence such as ( 090 ) - ( 534 ) - ( 00 ) - ( 00 ) .

 

 

# Pattern ( ZN >= 3.0.0 )


It is used to control the value of the desired type. This method should contain regular expression.

Parameters
String $ pattern Regular expression to check. You do not need to put container characters at the beginning and end.
String $ Extra For the use of extra characters such as i, s, x added at the end of regular expressions.
return this
Use of
Validation::pattern('[a-zA-Z0-9]+', 'i')->rules('name');

 

 

# Between /BetweenBoth ( ZN >= 5.3.5 )


Checks whether the grant is between the two specified numbers.

Parameters
float Min $ Small number.
float $ max Big number.
return this
Use of
Validation::between(100, 200)->rules('name');

It has to be between numbers on the Between check. In the BetweenBoth control, the numbers can be equal.

 

 

# Value ( ZN >= 3.0.0 )


It is used instead of parameter 3 of the Validation :: rules () method . It is used to set the name of the input name that appears in the generated error output.

Parameters
String $ Value The name of the input object to be displayed.
return this
Use of
Validation::validate('required')->compare(5, 100)->value('Name')->rules('name');

 

 

# Method ( ZN >= 3.0.0 )


Used in place of parameter 4 of Validation :: rules () method . The request type is set to post by default. This method is used to change this.

Parameters
String $ method The type of request method.
Options post , get , request
return this
Use of
Validation::validate('required')->method('get')->rules('name');

 

 

# Rules ( ZN >= 0.0.1 )


The main purpose of this method is to determine which control parameters the data from the form will pass through. If the data passes successfully from the control, the error () method returns false .

Parameters
String $ InputName The name of the sender of the object, post, or other method.
Array $ rules Filters to apply.
String $ Viewname The value of the input object.
return void
uses
Post::username('ExampleUser');
Post::password('1234');

Validation::rules('username', ['required', 'email'], 'Username:');
Validation::rules('password', ['required', 'minchar' => 8, 'maxhar' => 32], 'Username:');

output( Validation::error() );
0 => string 'Username: field is not valid email address!' (length = 45 ) ,
1 => string 'Username: area of ​​at least 8 characters long!' (length = 53 )

 

 

# Error ( ZN >= 0.0.1 )


It is used to obtain information about the success of the data control after the validation. This method is usually used to give an informational message with a string parameter.

Parameters
String $ type = 'array' The data type of the error output.
array The error output returns in the array type.
string The error output returns in the string type.
return Mixed
uses
echo Validation::error('string');
output( Validation::error() );

 

 

# Check ( ZN >= 5.4.2 )


Used to control the rules created by the validate () method of objects belonging to the form library .

Parameters
String $ submitName = NULL Submit the form and submit the button name value.
return Bool
uses
<?php namespace Project\Controllers;

use Validation, Post;

class Home extends Controller
{
    public function main(String $params = NULL)
    {
        if( ! Validation::check('submit') )
        {
            View::error(Validation::error('string'));
        }
    }
}

 

 

# Standard Validation Usage


Generally, the use of Validation is used to check the values ​​of the form posted from a view page. Accordingly, let's edit our codes assuming that we have a controller and a view page as below.

Prepare the Form

Prepare your form to send data. 

View: Views / contact / main.wizard.php
@Form::open('test'):
@Form::placeholder('Name')->text('name'): <br>
@Form::placeholder('Subject')->textarea('subject'): <br>
@Form::submit('sendSubmit', 'Send'):
@Form::close():

@if( ! empty($validationError) ):
    @$validationError:
@endif:
Prepare the Controller

Prepare the controller that processes the incoming form data. 

Controller:  Controllers / contact.php
<?php namespace Project\Controllers;

use Validation, DB, Post;

class Contact extends Controller
{
    public function main(String $params = NULL)
    {
        if( Post::sendSubmit() )
        {
            Validation::validate('required')
                      ->compare(2, 250)
                      ->secure('xss', 'injection')
                      ->value('Name : ')
                      ->rules('name');

            Validation::validate('required')
                      ->compare(5, 250)
                      ->secure('script', 'xss')
                      ->value('Subject : ')
                      ->rules('subject');

            if( ! $validationError = Validation::error('string') )
            {
                DB::insert('post:contact');               
            }    
        } 

        View::validationError($validationError ?? NULL);    
    }
}

 

 

# Form Validation Usage


In this type of use, the control of the form data is done on the controller with the Form :: validate ()  method on the view instead of Validation :: rules () .

Prepare the Form

Prepare your form to send data. 

View: Views / contact / main.wizard.php
@Form::open('test'):
@Form::placeholder('Name')
     ->validate('xss', 'injection', ['minchar' => 2])
     ->text('name'): <br>
@Form::placeholder('Subject')
     ->validate('script', ['minchar' => 5, 'maxchar' => 250])
     ->textarea('subject'): <br>
@Form::submit('sendSubmit', 'Send'):
@Form::close():

@if( ! empty($validationError) ):
    @$validationError:
@endif:
Prepare the Controller

Prepare the controller that processes the incoming form data. 

Controller:  Controllers / contact.php
<?php namespace Project\Controllers;

use Validation;

class Home extends Controller
{
    public function main(String $params = NULL)
    {
        if( ! Validation::check('sendSubmit') )
        {
            # your codes...
            View::validationError(Validation::error('string'));
        }
    }
}

 

 

# Validator ( ZN> = 4.0.23 )


It is the library created with the purpose of controlling the data. This section will explain the use of the Validator :: library for normal data.

 

 

# Methods


Bool phone ( String $ data , String $ pattern = NULL )
Bool numeric ( String $ data )
Bool alpha ( String $ data )
Bool alnum ( String $ data )
Bool identity ( Int $ no )
Bool email ( String $ data )
Bool url ( String $ data )
Bool specialChar ( String $ data )
Bool maxchar ( String $ data , Int $ char )
Bool minchar ( String $ data , Int $ char )

 

 

# Phone ( ZN> = 4.0.23 )


It checks whether the certificate contains telephone information.

Parameters
String $ data Data to check.
String $ pattern = NULL Which one will be checked according to the pattern.
return Bool
Examples
echo Validator::phone('1231');
echo Validator::phone('32343234234');
echo Validator::phone('123-234', ' *- - ');
echo Validator::phone('123-23-23', ' *- - '); 
0
1
0
1

 

 

# Numeric ( ZN >= 4.0.23 )


It is checked whether the data is numerical data.

Parameters
String $ data Data to check.
return Bool
Examples
echo Validator::numeric('1231');
echo Validator::numeric('a234');
echo Validator::numeric('234'); 
1
0
0

 

 

# Alpha ( ZN >= 4.0.23 )


It is checked whether the data is alphabetic data.

Parameters
String $ data Data to check.
return Bool
Examples
echo Validator::alpha('1231');
echo Validator::alpha('a234');
echo Validator::alpha('abcd'); 
0
0
1

 

 

# Aluminum ( ZN >= 4.0.23 )


It veyais checked whether the data is alphanumeric data.

Parameters
String $ data Data to check.
return Bool
Examples
echo Validator::alnum('1231');
echo Validator::alnum('a234');
echo Validator::alnum('abcd');
echo Validator::alnum('?+y12');
1
1
1
0

 

 

# Identity ( ZN >= 4.0.23 )


It checks whether the certificate is an identification number.

Parameters
String $ data Data to check.
return Bool
Examples
echo Validator::identity(12312311231);
echo Validator::identity('12312312');
0
0

When you enter a real ID number, you can see the result is 1 .

 

 

# Email ( ZN> = 4.0.23 )


Check whether the e-mail is delivered.

Parameters
String $ data Data to check.
return Bool
Examples
echo Validator::email('robot@znframework');
echo Validator::email('robot@znframework.com');
0
1

 

 

# URL ( ZN> = 4.0.23 )


It checks to see if it is a url.

Parameters
String $ data Data to check.
return Bool
Examples
echo Validator::url('www.znframework.com');
echo Validator::url('https://www.znframework.com');
0
1

 

 

# SpecialChar ( ZN >= 4.0.23 )


It checks whether there are special characters in the file.

Parameters
String $ data Data to check.
return Bool
Examples
echo Validator::specialChar('abc+');
echo Validator::specialChar('abc');
1
0

 

 

# Minchar ( ZN >= 4.0.23 )


The given minimum length value is checked. trueReturns as long as the specified value is equal and large .

Parameters
String $ data Data to check.
Int $ length Character length.
return Bool
Examples
echo Validator::minchar('abc', 5);
echo Validator::minchar('abc', 2);
0
1

 

 

# Maxchar ( ZN >= 4.0.23 )


The maximum length value of the output is checked. trueReturns as long as the specified value is equal and small .

Parameters
String $ data Data to check.
Int $ length Character length.
return Bool
Examples
echo Validator::maxchar('abc', 5);
echo Validator::maxchar('abc', 2);
1
0

 

 

# Validate ( ZN >= 4.0.23 )


This library is a control library for sequential use of the Validator :: library. It can use all the methods in the Validator :: library.

 

 

# Methods


this data ( String $ data )
Bool get ( Void )
Array status ( Void )

 

 

# Data ( ZN >= 4.0.23 )


This is the method to enter the data to be checked.

Parameters
String $ data Data to check.
return this
Examples
$status = Validate::data('ExampleData')
                  ->maxchar(20)
                  ->minchar(5)
                  ->email()
                  ->get();

echo $status;
output( Validate::status() );
false
maxch is => boolean true (length = 4 ) ,
minchi is => boolean true (length = 4 ) ,
email    => boolean false (length = 5)

 

 

# Get ( ZN >= 4.0.23 )

Validate library filtering


to terminate transactions.

Parameters
void
return Bool

The above example is shown for use.

 

 

# Status ( ZN> = 4.0.23 )


The Validate library returns an array that tells you which filters are passed successfully and which are not.

Parameters
void
return Bool

The above example is shown for use.