PhpUnit断言如果字符串包含数字字符

Just wondering on how to test if a string contains on numeric characters.

I tried

$testdata = [           
   'ver'  => '087'
];

$this->assertRegExp('/0-9/',$testdata['ver']);

but the above fails.

All numbers would have to be:

^[0-9]+$

Ranges have to be enclosed in brackets. However, just [0-9] is just going to match anything with one number.

You can also use \d to represent any digit.

^\d+$

If you want to take advantage of PHP's is_numeric check, you could also perform the assertion this way:

$this->assertTrue(is_numeric($testdata['ver']));