<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;
use Exception;

class AsnFormat implements Rule
{

    public function passes($attribute, $value)
    {

        if (!is_scalar($value)) {
            return false;
        }

        try {
            return preg_match('/^(?:ASN|AS)?\d+$/iD', (string) $value) === 1;
        }
        catch(Exception $ex) {
            return false;
        }

    }

    public function message()
    {
        return 'The :attribute must be a valid ASN.';
    }
}
