duanniubeng2265 2018-10-10 23:28
浏览 136
已采纳

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.

  • 写回答

1条回答 默认 最新

  • dongyou9373 2018-10-10 23:53
    关注

    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']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)