Forum Moderators: coopster
nnnn/n
nnnn/nn
nnnn/nnn
nnnn/nnnn
nnnn/nnnnn
nnnn/n/a
nnnn/nn/a
nnnn/nnn/a
nnnn/nnnn/a
nnnn/nnnnn/a
[a-Z] is synonymous with [a-zA-Z]
$app_selwynid = array('2014/931','2013/8809','2007/8694/a','1999/1/a','323/323232323','2000/11/xzxz','12xx/12xx','2010/12xx12/a');
foreach ($app_selwynid as $app_id) {
//if (preg_match("/[0-9]{4}\/[0-9]{1,5}|(\/[a-zA-Z]{1})/",$app_id)) {
//preg_match("/\d{4}\/\d{1,5}(?:\/[a-Z])?/"
//preg_match("~\d{4}\/\d{1,5}(?:\/[a-Z])?~"
if (@preg_match("/~\d{4}\/\d{1,5}(?:\/[a-Z])?~/", $app_id)) {
echo $app_id.' - valid bc number'."\n\n";
} else {
echo $app_id.' - invalid bc number'."\n\n";
}
}
2014/931 - invalid bc number
2013/8809 - invalid bc number
2007/8694/a - invalid bc number
1999/1/a - invalid bc number
323/323232323 - invalid bc number
2000/11/xzxz - invalid bc number
12xx/12xx - invalid bc number
2010/12xx12/a - invalid bc number
$app_selwynid = array('2014/931','2013/8809','2007/8694/a','1999/1/a','323/323232323','2000/11/xzxz','12xx/12xx','2010/12xx12/a','1212121/121','12121212/1211/w','1234/12/');
foreach ($app_selwynid as $app_id) {
if (preg_match("/\b[0-9]{4}\/[0-9]{1,5}\b(|\/[a-zA-Z]{1}\b)?/",$app_id)) {
echo $app_id.' - valid bc number'."\n\n";
} else {
echo $app_id.' - invalid bc number'."\n\n";
}
}
2014/931 - valid bc number
2013/8809 - valid bc number
2007/8694/a - valid bc number
1999/1/a - valid bc number
323/323232323 - invalid bc number
2000/11/xzxz - valid bc number [should be invalid]
12xx/12xx - invalid bc number
2010/12xx12/a - invalid bc number
1212121/121 - invalid bc number
12121212/1211/w - invalid bc number
1234/12/ - valid bc number [should be invalid]
Warning: preg_match_all(): Compilation failed: range out of order in character class at offset 20 in E:\localhost\alpha1_v1\test.php on line 13
2014/931 - invalid bc number
Warning: preg_match(): Compilation failed: range out of order in character class at offset 20 in E:\localhost\alpha1_v1\test.php on line 13
2013/8809 - invalid bc number
[A-z]
would be synonymous with [A-Z\[\\\]\^_`a-z]
(neatly encompassing most escapable RegEx characters!) Contrariwise
[a-Z]
is synonymous with nothing
$testArray = array('2014/931','2013/8809','2007/8694/a','1999/1/a','323/323232323','2000/11/xzxz','12xx/12xx','2010/12xx12/a');
foreach($testArray as $testItem) {
echo "{$testItem}: " . ((preg_match('~\d{4}/\d{1,5}(?:/[A-z])?~', $testItem))? 'Valid' : 'Invalid') . "\n";
}
2014/931: Valid
2013/8809: Valid
2007/8694/a: Valid
1999/1/a: Valid
323/323232323: Invalid
2000/11/xzxz: Valid
12xx/12xx: Invalid
2010/12xx12/a: Valid
2014/931: Valid
2013/8809: Valid
2007/8694/a: Valid
1999/1/a: Valid
323/323232323: Invalid
2000/11/xzxz: Valid -- this should be invalid
12xx/12xx: Invalid
2010/12xx12/a: Valid -- this should be invalid
need the start of string and end of string markers