PHP code example of michaelbiberich / xmask

1. Go to this page and download the library: Download michaelbiberich/xmask library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaelbiberich / xmask example snippets




declare(strict_types=1);

;

$xmask = new Xmask('xxx456xxx', [
    'x' => '0-9',
]);

$pattern = $xmask->pattern();
// => string(67) "/^([0-9])([0-9])([0-9])456([0-9])([0-9])([0-9])$/"

preg_match($pattern, '123456789'); // => int(1)
preg_match($pattern, '123000789'); // => int(0)
preg_match($pattern, 'abc456789'); // => int(0)

// Examples: Value added tax identification numbers (VATINs)

$austriaVatinXmask = new Xmask('ATUxxxxxxxxx', [
    'x' => '0-9',
]);

$austriaVatinPattern = $austriaVatinXmask->pattern();

preg_match($austriaVatinPattern, 'ATU123456789'); // => int(1)
preg_match($austriaVatinPattern, 'ATU12345678'); // => int(0)

$cyprusVatinXmask = new Xmask('CYxxxxxxxxX', [
    'x' => '0-9',
    'X' => 'A-Z',
]);

$cyprusVatinPattern = $cyprusVatinXmask->pattern();
// => string(96) "/^CY([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([A-Z])$/"

preg_match($cyprusVatinPattern, 'CY12345678A'); // => int(1)
preg_match($cyprusVatinPattern, 'CY123456789'); // => int(0)