> For the complete documentation index, see [llms.txt](https://composer.notanumber.digital/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://composer.notanumber.digital/laravel-general-package/validation.md).

# Validation

## Settings

Start of by importing the controller where you are using it

```php
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.&#x20;

Example:

```php
$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

```php
$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:

```php
$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:

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

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

// Will echo: '1234AB'
```
