The only possible value this field can have is P
followed by a 0,1,2,3,4
and 0,1,2,3,4
$option_print = $this->input->post('print');
if (!preg_match('^/p[0-4][0-4]/', $option_print))
{ redirect('#example'); } else { ... }
Example of VALID inputs:
p00
-> validp10
-> validExample of INVALID inputs:
v00
-> invalidf10
-> invalidffs
-> invalidSo how should my regex
be properly structured to filter for VALID inputs?
How about this:
!preg_match('/^p[0-4][0-4]$/', $option_print)
Or even this:
!preg_match('/^p[0-4]{2}$/', $option_print)
Your regex is almost perfectly valid. But you put ^
before /
that why it doesn't work
'/^p[0-4][0-4]$/'