您的位置:首页 > 编程语言 > Python开发

Python 正则表达式验证特定范围的数字

2014-09-04 11:13 274 查看
1. 1 to 12 (hour or month)
^(1[0-2]|[1-9])$

2. 1 to 24 (hour)
^(2[0-4]|1[0-9]|[1-9])$

3. 1 to 31 (day of the month)
^(3[01]|[12][0-9]|[1-9])$

4. 1 to 53 (week of the year)
^(5[0-3]|[1-4][0-9]|[1-9])$

5. 0 to 59 (minute or second)
^[1-5]?[0-9]$

6. 0 to 100 (percentage)
^(100|[1-9]?[0-9])$

7. 1 to 100
^(100|[1-9][0-9]?)$

8. 32 to 126 (printable ASCII codes)
^(12[0-6]|1[01][0-9]|[4-9][0-9]|3[2-9])$

9. 0 to 127 (nonnegative signed byte)
^(12[0-7]|1[01][0-9]|[1-9]?[0-9])$

10. -128 to 127 (sinned byte)
^(12[0-7]|1[01][0-9]|[1-9]?[0-9]|-(12[08]|1[01][0-9]|[1-9]?[0-9]))$

11. 0 to 255 (unsigned byte)
^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$

12. 1 to 366 (day of the year)
^(36[0-6]|3[0-5][0-9]|[12][0-9]{2}|[1-9][0-9]?)$

13. 1900 to 2099 (year)
^(19|20)[0-9]{2}$

14. 0 to 32967 (nonnegative signed word)
^(3276[0-7]|327[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$

15. -32768 to 32767 (signed word)
^(3276[0-7]|3297[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|[1-9][0-9]{1,3}|[0-9]|-(3276[0-8]|3297[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|[1-9][0-9]{1,3}|[0-9]))$

16. 0 to 65535 (unsigned word)
^(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: