⌨️Validation

Settings

Start of by importing the controller where you are using it

use NaN\NanGeneralController\Controllers\ValidationController;

Email

An standardized way to validate email addresses. It validates on basic faults like not a valid format, but it also checks if the domain can be mailed by checking A and MX records.

Example:

$email = 'info@example.com';
$ValidationController = new ValidationController();
$result = $ValidationController->validateEmail($email);

Tip: Set the debug paramater to true to see what the validation fails on

$ValidationController->validateEmail($email, true);

// invalid_mx_or_a_record
// invalid_domain
// invalid_pregmatch_validate
// invalid_filter_validate

Phone

An easy no-hassle way to validate a phone number. Pass a phone number as the first parameter and you can set the second parameter to true to allow the phone number to have a country code like +31

Example:

$number = '+31612345678';
$ValidationController = new ValidationController();
$result = $ValidationController->validatePhoneNumber($number, true);

Zipcode

A way to validate, and properly format in return, Dutch zipcodes. Pass a zipcode as paramater and in return you will get false if the zipcode is not correct. Else you will get a zipcode formatted 1111AA

Example:

$zipcode = '  1234 aB';
$ValidationController = new ValidationController();
$zipcode = $ValidationController->validateZipcode($zipcode);

if(false !== $zipcode {
    echo $zipcode;
}

// Will echo: '1234AB'

Last updated