isHex.
This commit is contained in:
parent
c6c5cc9251
commit
ab90423aab
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user