Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More IDnumber testing

  • Loading branch information...
commit bfdd1ebe738354c73d54da8b27340e8f658d6be3 1 parent 7758707
@c9s authored
View
7 src/ValidationKit/TW/IDNumberValidator.php
@@ -8,11 +8,9 @@ class IDNumberValidator extends Validator
public function calculateChecksum($str)
{
$c = (int) $str[0] * 1;
- for($i = 1; $i < 11; $i++ ) {
+ for($i = 1; $i < 11; $i++ )
$c += $str[$i] * (10-$i);
- }
- $mod = $c % 10;
- return 10 - $mod;
+ return 10 - ($c % 10);
}
public function validate($val) {
@@ -20,7 +18,6 @@ public function validate($val) {
return $this->invalid('length_error');
if( ! preg_match('#^[a-zA-Z]\d{9}$#i',$val) )
return $this->invalid('format_error');
-
$a = stripos('ABCDEFGHJKLMNPQRSTUVWXYZIO',$val[0]) + 10;
$c = $this->calculateChecksum($a . substr($val,1));
if( $c == substr($val,-1) )
View
2  tests/ValidationKit/TW/IDNumberValidatorTest.php
@@ -10,6 +10,8 @@ function test()
ok($v->validate('A178161208'));
ok($v->validate('A157354749'));
ok($v->validate('I155729562'));
+ not_ok($v->validate('BBBB'));
+ not_ok($v->validate('B123456789'));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.