- preg_match: documentation ( source)
<?php
class PilotId
{
protected $pid;
/**
* @param PilotId|string $pid
*/
public function __construct($pid){
if(!preg_match("^(AFA|PAY)([0-9]{4})$", (string)$pid))
throw new \InvalidArgumentException('Invalid PID');
$this->pid = $pid;
}
function __toString(){
return $this->pid;
}
}