how to use preg_match to check whole text

前端 未结 2 1044
执笔经年
执笔经年 2021-01-17 03:12

Hi i have a problem with preg_match function.
i want to check whole text against pattern and return true if whole text matched with pattern and false for not matched or

相关标签:
2条回答
  • 2021-01-17 03:54

    Just change the pattern like this:

    "/^[\d]+$/"
    

    Remember that:

    • ^: means the start of the string
    • $: means the end of the string
    0 讨论(0)
  • 2021-01-17 04:11

    You need to use ^ to indicate the start of the string and $ for the end

    if (preg_match("/^[\d]+$/","99ab")) return true; 
    else return false;
    
    0 讨论(0)
提交回复
热议问题