This commit is contained in:
sc0Vu 2017-12-28 11:49:54 +08:00
parent c6c5cc9251
commit ab90423aab
2 changed files with 32 additions and 1 deletions

View File

@ -178,6 +178,17 @@ class Utils
return true;
}
/**
* isHex
*
* @param string
* @return bool
*/
public static function isHex($value)
{
return (is_string($value) && preg_match('/^(0x)?[a-f0-9]*$/', $value) === 1);
}
/**
* sha3
* keccak256

View File

@ -366,4 +366,24 @@ class UtilsTest extends TestCase
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
}
/**
* testIsHex
*
* @return void
*/
public function testIsHex()
{
$isHex = Utils::isHex($this->testHex);
$this->assertTrue($isHex);
$isHex = Utils::isHex('0x' . $this->testHex);
$this->assertTrue($isHex);
$isHex = Utils::isHex('hello world');
$this->assertFalse($isHex);
}
}