forked from lkallas/estonianpin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.php
26 lines (18 loc) · 853 Bytes
/
validation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Lkallas\Estonianpin\EstonianPIN;
$estonianPIN = new EstonianPIN();
$pin = '49901150062';
// Simple format validation using regular expression.
$regexPassed = $estonianPIN->isValidatedByRegex($pin);
echo 'Validation using regular expression ' . ($regexPassed ? 'PASSED' : 'FAILED') . PHP_EOL;
// Advanced validation (calculates and validates also the control number and birth date).
$validated = $estonianPIN->validate($pin);
echo 'Validation with control number check ' . ($validated ? 'PASSSED' : 'FAILED') . PHP_EOL;
// Validation that throws corresponding exceptions on validation failures.
try {
$estonianPIN->validateWithExceptions($pin);
echo $pin . ' is a valid Estonian Personal Identification Code' . PHP_EOL;
} catch (Exception $exc) {
echo $exc->getMessage();
}