Skip to content

Commit

Permalink
Merge pull request #25 from fusic/alpha_numeric_symbols
Browse files Browse the repository at this point in the history
alphaNumeric系の関数作成
  • Loading branch information
Junkins authored Dec 16, 2016
2 parents 41dac65 + 1e0c17d commit 2aa627a
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Validation/ApollonValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,45 @@ public static function numeric($check, $limit = 2147483647)
return abs($check) <= $limit;
}

/**
* alphaNumeric
* 半角英数チェック
* CoreのalphaNumericは日本語を通過させてしまうため、上書き
* @access public
* @author ito
* @param string $check
* @return boolean
*/
public static function alphaNumeric($check)
{
$regex = '/^[a-zA-Z0-9]+$/u';
return (bool) self::_check($check, $regex);
}

/**
* alphaNumericSymbols
* 半角英数記号チェック
* 参考URL:http://defindit.com/ascii.html
* @access public
* @author ito
* @param string $check
* @return boolean
*/
public static function alphaNumericSymbols($check)
{
// \x21-\x2f
// ! " # $ % & ' ( ) * + , - . /
// \x3a-\x40
// : ; < = > ? @
// \x5b-\x60
// [ \ ] ^ _ `
// \x7b-\x7e
// { | } ~
// 半角スペース、全角スペースは認めない
$regex = '/^[a-zA-Z0-9\x21-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]+$/u';
return (bool) self::_check($check, $regex);
}

/**
* naturalNumber
* 数値チェック
Expand Down
162 changes: 162 additions & 0 deletions tests/TestCase/Validation/ApollonValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,168 @@ public function test_numeric()
$this->assertFalse(ApollonValidation::numeric('12345', '12344'));
}

/**
* test_alphaNumeric
* @dataProvider dataProvider_alphaNumeric
* @return void
*/
public function test_alphaNumeric($check, $expected)
{
$reault = ApollonValidation::alphaNumeric($check);
$this->assertEquals($reault, $expected);
}
public function dataProvider_alphaNumeric()
{
return [
// 半角英字小文字
['abcdefghijklmnopqrstuvwxyz', true],
// 半角英字大文字
['ABCDEFGHIJKLMNOPQRSTUVWXYZ', true],
// 半角数値(文字列)
['0123456789', true],
// 半角数値(数値)
[1234567890, true],
// 半角数値(0)
[0, true],
// 半角英字小文字 + 半角英字大文字
['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', true],
// 半角英字小文字 + 半角英字大文字 + 半角数字
['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', true],
// 全角英字小文字
['abcdefghijklmnopqrstuvwxyz', false],
// 全角英字大文字
['ABCDEFGHIJKLMNOPQRSTUVWXYZ', false],
// 全角数値大文字
['0123456789', false],
// 半角数値(マイナス)
[-1234567890, false],
// 全角ひらがな
['あいうえおかきくけこ', false],
// 全角カタカナ
['アイウエオカキクケコ', false],
// 半角カタカナ
['アイウエオヴ', false],
// 全角スペース
[' ', false],
// 半角スペース
[' ', false],
// 記号
['!', false],
['"', false],
['#', false],
['$', false],
['%', false],
['&', false],
["'", false],
['(', false],
[')', false],
['*', false],
['+', false],
[',', false],
['-', false],
['.', false],
['/', false],
[':', false],
[';', false],
['<', false],
['=', false],
['>', false],
['?', false],
['@', false],
['[', false],
['\\', false],
[']', false],
['^', false],
['_', false],
['`', false],
['{', false],
['|', false],
['}', false],
['~', false],
];
}

/**
* test_alphaNumericSymbols
* @dataProvider dataProvider_alphaNumericSymbols
* @return void
*/
public function test_alphaNumericSymbols($check, $expected)
{
$reault = ApollonValidation::alphaNumericSymbols($check);
$this->assertEquals($reault, $expected);
}
public function dataProvider_alphaNumericSymbols()
{
return [
// 半角英字小文字
['abcdefghijklmnopqrstuvwxyz', true],
// 半角英字大文字
['ABCDEFGHIJKLMNOPQRSTUVWXYZ', true],
// 半角数値(文字列)
['0123456789', true],
// 半角数値(数値)
[1234567890, true],
// 半角数値(0)
[0, true],
// 記号
['!', true],
['"', true],
['#', true],
['$', true],
['%', true],
['&', true],
["'", true],
['(', true],
[')', true],
['*', true],
['+', true],
[',', true],
['-', true],
['.', true],
['/', true],
[':', true],
[';', true],
['<', true],
['=', true],
['>', true],
['?', true],
['@', true],
['[', true],
['\\', true],
[']', true],
['^', true],
['_', true],
['`', true],
['{', true],
['|', true],
['}', true],
['~', true],
// 半角英字小文字 + 半角英字大文字
['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', true],
// 半角英字小文字 + 半角英字大文字 + 半角数字
['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', true],
// 半角英字小文字 + 半角英字大文字 + 半角数字 + 記号
['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!"#$%&()*+,-.:;<=>?@[\]^_`{|}~',true],
// 全角英字小文字
['abcdefghijklmnopqrstuvwxyz', false],
// 全角英字大文字
['ABCDEFGHIJKLMNOPQRSTUVWXYZ', false],
// 全角数値大文字
['0123456789', false],
// 全角ひらがな
['あいうえおかきくけこ', false],
// 全角カタカナ
['アイウエオカキクケコ', false],
// 半角カタカナ
['アイウエオヴ', false],
// 全角スペース
[' ', false],
// 半角スペース
[' ', false],
];
}

/**
* test_naturalNumber method
*
Expand Down

0 comments on commit 2aa627a

Please sign in to comment.