Regex allow a string to only contain numbers 0 - 9 and limit length to 45

后端 未结 8 848
轮回少年
轮回少年 2020-12-02 13:57

I am trying to create a regex to have a string only contain 0-9 as the characters and it must be at least 1 char in length and no more than 45. so

8条回答
  •  醉话见心
    2020-12-02 14:54

    The first matches any number of digits within your string (allows other characters too, i.e.: "039330a29"). The second allows only 45 digits (and not less). So just take the better from both:

    ^\d{1,45}$
    

    where \d is the same like [0-9].

提交回复
热议问题