PageRenderTime 130ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/github.com/thedevsaddam/govalidator/regex_patterns.go

https://bitbucket.org/logicielsolutions/lpm
Go | 74 lines | 50 code | 3 blank | 21 comment | 0 complexity | 422e8ecf27b6585797f179f88b0668cc MD5 | raw file
Possible License(s): BSD-2-Clause, MIT, Apache-2.0, BSD-3-Clause
  1. package govalidator
  2. import (
  3. "regexp"
  4. )
  5. const (
  6. // Alpha represents regular expression for alpha chartacters
  7. Alpha string = "^[a-zA-Z]+$"
  8. // AlphaDash represents regular expression for alpha chartacters with underscore and ash
  9. AlphaDash string = "^[a-zA-Z0-9_-]+$"
  10. // AlphaNumeric represents regular expression for alpha numeric chartacters
  11. AlphaNumeric string = "^[a-zA-Z0-9]+$"
  12. // CreditCard represents regular expression for credit cards like (Visa, MasterCard, American Express, Diners Club, Discover, and JCB cards). Ref: https://stackoverflow.com/questions/9315647/regex-credit-card-number-tests
  13. CreditCard string = "^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$"
  14. // Coordinate represents latitude and longitude regular expression
  15. Coordinate string = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?),\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$" // Ref: https://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates
  16. // CSSColor represents css valid color code with hex, rgb, rgba, hsl, hsla etc. Ref: http://www.regexpal.com/97509
  17. CSSColor string = "^(#([\\da-f]{3}){1,2}|(rgb|hsl)a\\((\\d{1,3}%?,\\s?){3}(1|0?\\.\\d+)\\)|(rgb|hsl)\\(\\d{1,3}%?(,\\s?\\d{1,3}%?){2}\\))$"
  18. // Date represents regular expression for valid date like: yyyy-mm-dd
  19. Date string = "^(((19|20)([2468][048]|[13579][26]|0[48])|2000)[/-]02[/-]29|((19|20)[0-9]{2}[/-](0[469]|11)[/-](0[1-9]|[12][0-9]|30)|(19|20)[0-9]{2}[/-](0[13578]|1[02])[/-](0[1-9]|[12][0-9]|3[01])|(19|20)[0-9]{2}[/-]02[/-](0[1-9]|1[0-9]|2[0-8])))$"
  20. // DateDDMMYY represents regular expression for valid date of format dd/mm/yyyy , dd-mm-yyyy etc.Ref: http://regexr.com/346hf
  21. DateDDMMYY string = "^(0?[1-9]|[12][0-9]|3[01])[\\/\\-](0?[1-9]|1[012])[\\/\\-]\\d{4}$"
  22. // Email represents regular expression for email
  23. Email string = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$"
  24. // Float represents regular expression for finding fload number
  25. Float string = "^[+-]?([0-9]*[.])?[0-9]+$"
  26. // IP represents regular expression for ip address
  27. IP string = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
  28. // IPV4 represents regular expression for ip address version 4
  29. IPV4 string = "^([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/([0-9]|[1-2][0-9]|3[0-2]))?$"
  30. // IPV6 represents regular expression for ip address version 6
  31. IPV6 string = `^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$`
  32. // Latitude represents latitude regular expression
  33. Latitude string = "^(\\+|-)?(?:90(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\\.[0-9]{1,6})?))$"
  34. // Longitude represents longitude regular expression
  35. Longitude string = "^(\\+|-)?(?:180(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\\.[0-9]{1,6})?))$"
  36. // Numeric represents regular expression for numeric
  37. Numeric string = "^[0-9]+$"
  38. // URL represents regular expression for url
  39. URL string = "^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$" // Ref: https://stackoverflow.com/questions/136505/searching-for-uuids-in-text-with-regex
  40. // UUID represents regular expression for UUID
  41. UUID string = "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$"
  42. // UUID3 represents regular expression for UUID version 3
  43. UUID3 string = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
  44. // UUID4 represents regular expression for UUID version 4
  45. UUID4 string = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
  46. // UUID5 represents regular expression for UUID version 5
  47. UUID5 string = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
  48. )
  49. var (
  50. regexAlpha = regexp.MustCompile(Alpha)
  51. regexAlphaDash = regexp.MustCompile(AlphaDash)
  52. regexAlphaNumeric = regexp.MustCompile(AlphaNumeric)
  53. regexCreditCard = regexp.MustCompile(CreditCard)
  54. regexCoordinate = regexp.MustCompile(Coordinate)
  55. regexCSSColor = regexp.MustCompile(CSSColor)
  56. regexDate = regexp.MustCompile(Date)
  57. regexDateDDMMYY = regexp.MustCompile(DateDDMMYY)
  58. regexEmail = regexp.MustCompile(Email)
  59. regexFloat = regexp.MustCompile(Float)
  60. regexNumeric = regexp.MustCompile(Numeric)
  61. regexLatitude = regexp.MustCompile(Latitude)
  62. regexLongitude = regexp.MustCompile(Longitude)
  63. regexIP = regexp.MustCompile(IP)
  64. regexIPV4 = regexp.MustCompile(IPV4)
  65. regexIPV6 = regexp.MustCompile(IPV6)
  66. regexURL = regexp.MustCompile(URL)
  67. regexUUID = regexp.MustCompile(UUID)
  68. regexUUID3 = regexp.MustCompile(UUID3)
  69. regexUUID4 = regexp.MustCompile(UUID4)
  70. regexUUID5 = regexp.MustCompile(UUID5)
  71. )