List of common regular expressions

  1. Validation numbers: ^[0-9]*$
  2. Verify n digits: ^\d{n}$
  3. Verify at least n digits: ^\d{n,}$
  4. Verify mn digits: ^\d{m,n}$
  5. Validate zero and non-zero leading numbers: ^(0|[1-9][0-9]*)$
  6. Validate positive real numbers with two decimal places: ^[0-9]+(.[0-9]{2})?$
  7. Verify positive real numbers with 1-3 decimal places: ^[0-9]+(.[0-9]{1,3})?$
  8. Validate non-zero positive integers: ^\+?[1-9][0-9]*$
  9. Validate non-zero negative integers: ^\-[1-9][0-9]*$
  10. Validate non-negative integers (positive integer + 0 ): ^\d+$
  11. Validate non-positive integers (negative integers + 0 ): ^((-\d+)|(0+))$
  12. Validate characters of length 3 : ^.{3}$
  13. Validate a string of 26 English letters: ^[A-Za-z]+$
  14. Validate a string of 26 uppercase English letters: ^[AZ]+$
  15. Validate a string consisting of 26 lowercase English letters: ^[az]+$
  16. Validate a string consisting of numbers and 26 English letters: ^[A-Za-z0-9]+$
  17. Validate a string consisting of numbers, 26 English letters or underscores: ^\w+$
  18. Start with a letter, length between 6-18 , can only contain characters, numbers and underscores : ^[a-zA-Z]\w{5,17}$
  19. Verify that it contains characters such as ^%&',;=?$\": [^%&',;=?$\x22]+
  20. Verify Chinese characters: ^[\u4e00-\u9fa5],{0,}$
  21. Verify Email Address: ^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
  22. 验证InternetURL^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
  23. Verify phone number: ^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}) |(0\d{2}-\d{7,8})|(0\d{3}-\d{7,8})$
  24. Verify ID number (15 or 18 digits): ^\d{15}|\d{18}|\d{17}X$
  25. Verify the 12 months of a year: ^(0?[1-9]|1[0-2])$ The correct format is: "01"-"09" and "1" "12"
  26. Verify the 31 days of a month: ^((0?[1-9])|((1|2)[0-9])|30|31)$ The correct format is: 01, 09 and 1, 31.
  27. Integer: ^-?\d+$
  28. Non-negative float (positive float + 0 ): ^\d+(\.\d+)?$
  29. Non-positive float (negative float + 0 ): ^((-\d+(\.\d+)?)|(0+(\.0+)?))$
  30. Number of floating points ^ (-(([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0- 9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *))) $
  31. float ^(-?\d+)(\.\d+)?$      

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325716639&siteId=291194637