# 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'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://composer.notanumber.digital/laravel-general-package/validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
