Update plate number validation, according to specifications. #211
This commit is contained in:
parent
ce520ebf51
commit
2a501e60e4
1 changed files with 27 additions and 20 deletions
|
|
@ -162,30 +162,37 @@ class Warranty
|
||||||
// trim and make upper case
|
// trim and make upper case
|
||||||
$clean_plate = strtoupper(trim($plate));
|
$clean_plate = strtoupper(trim($plate));
|
||||||
|
|
||||||
// remove invalid characters
|
// check if alphanumeric, max length is 11, no spaces
|
||||||
$clean_plate = preg_replace("/[^A-Z0-9]/", '', $clean_plate);
|
$res = preg_match("/^[A-Z0-9]{1,11}+$/", $clean_plate);
|
||||||
|
|
||||||
// check for 4 to 5 digit diplomatic plate
|
|
||||||
$res = preg_match("/^[0-9]{4,5}$/", $clean_plate);
|
|
||||||
if ($res)
|
|
||||||
return $clean_plate;
|
|
||||||
|
|
||||||
// ABC-1234 or ABC-123 or ABC-12 format
|
|
||||||
$res = preg_match("/^[A-Z]{3}[0-9]{2,4}$/", $clean_plate);
|
|
||||||
if ($res)
|
|
||||||
return $clean_plate;
|
|
||||||
|
|
||||||
// AB-123 or AB-12345 or AB-1234 format (motorcycles)
|
|
||||||
$res = preg_match("/^[A-Z]{2}[0-9]{3,5}$/", $clean_plate);
|
|
||||||
if ($res)
|
|
||||||
return $clean_plate;
|
|
||||||
|
|
||||||
// 1234-AB format (motorcycles)
|
|
||||||
$res = preg_match("/^[0-9]{4}[A-Z]{2}$/", $clean_plate);
|
|
||||||
if ($res)
|
if ($res)
|
||||||
return $clean_plate;
|
return $clean_plate;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// remove invalid characters
|
||||||
|
//$clean_plate = preg_replace("/[^A-Z0-9]/", '', $clean_plate);
|
||||||
|
|
||||||
|
// check for 4 to 5 digit diplomatic plate
|
||||||
|
//$res = preg_match("/^[0-9]{4,5}$/", $clean_plate);
|
||||||
|
//if ($res)
|
||||||
|
// return $clean_plate;
|
||||||
|
|
||||||
|
// ABC-1234 or ABC-123 or ABC-12 format
|
||||||
|
//$res = preg_match("/^[A-Z]{3}[0-9]{2,4}$/", $clean_plate);
|
||||||
|
//if ($res)
|
||||||
|
// return $clean_plate;
|
||||||
|
|
||||||
|
// AB-123 or AB-12345 or AB-1234 format (motorcycles)
|
||||||
|
//$res = preg_match("/^[A-Z]{2}[0-9]{3,5}$/", $clean_plate);
|
||||||
|
//if ($res)
|
||||||
|
// return $clean_plate;
|
||||||
|
|
||||||
|
// 1234-AB format (motorcycles)
|
||||||
|
//$res = preg_match("/^[0-9]{4}[A-Z]{2}$/", $clean_plate);
|
||||||
|
//if ($res)
|
||||||
|
// return $clean_plate;
|
||||||
|
|
||||||
|
//return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPlateNumber($plate)
|
public function setPlateNumber($plate)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue