Can anyone help with regular expression for
ebsu/2009/1128
This what i came out with but is not working as i expected
/^ebsu(\/|-)\d{4}(\/|-)\d{4}$/
Please check and modifield my expression
thanks
Can anyone help with regular expression for
ebsu/2009/1128
This what i came out with but is not working as i expected
/^ebsu(\/|-)\d{4}(\/|-)\d{4}$/
Please check and modifield my expression
thanks
How do you want it to work?
I’m using preg_match($reg, $_POST[‘matric’]);
I expect the user to enter his matric number in the following format
ebsu/2009/1119
ebsu-2009-1119
ebsu-Is the starting follow by /forward slash of hypen-. I also expect a year 2009,2010 etc… follow by four digit number \d{4}
What about this?
#^ebsu[/-]\\d{4}[/-]\\d{4}$#
Of course, it also accepts ebsu-3333/1119 (- and /, and a year far far in the future).
If you want to check the value of the year more specifically, you could do
preg_match('#^ebsu[/-](\\d{4})[/-]\\d{4}$#', 'ebsu-2009/1128', $matches);
print_r($matches)
It would return
Array
(
[0] => ebsu-2009/1128
[1] => 2009
)
and then you can do more specific checks on the value in $matches[1].
Thanks very much: It does the work for me…