github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/f/regexp.go (about)

     1  package f
     2  
     3  import "regexp"
     4  
     5  // validator.go
     6  // Basic regular expressions for validating strings.
     7  
     8  const (
     9  	RxTagName           string = "valid"
    10  	RxEmail             string = "^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
    11  	RxCreditCard        string = "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|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}|6[27][0-9]{14})$"
    12  	RxISBN10            string = "^(?:[0-9]{9}X|[0-9]{10})$"
    13  	RxISBN13            string = "^(?:[0-9]{13})$"
    14  	RxUUID3             string = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
    15  	RxUUID4             string = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
    16  	RxUUID5             string = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
    17  	RxUUID              string = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    18  	RxAlpha             string = "^[a-zA-Z]+$"
    19  	RxAlphaNumeric      string = "^[a-zA-Z0-9]+$"
    20  	RxAlphaDash         string = `^(?:[\w-]+)$`
    21  	RxNumeric           string = "^[0-9]+$"
    22  	RxInt               string = "^(?:[-+]?(?:0|[1-9][0-9]*))$"
    23  	RxFloat             string = "^(?:[-+]?(?:[0-9]+))?(?:\\.[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"
    24  	RxCnMobile          string = `^1\d{10}$`
    25  	RxHexadecimal       string = "^[0-9a-fA-F]+$"
    26  	RxHexColor          string = "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
    27  	RxRGBColor          string = "^rgb\\(\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*\\)$"
    28  	RxASCII             string = "^[\x00-\x7F]+$"
    29  	RxMultiByte         string = "[^\x00-\x7F]"
    30  	RxFullWidth         string = "[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"
    31  	RxHalfWidth         string = "[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]"
    32  	RxBase64            string = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
    33  	RxPrintableASCII    string = "^[\x20-\x7E]+$"
    34  	RxDataURI           string = "^data:.+\\/(.+);base64$" // `^data:.+/(.+);base64,(?:.+)`
    35  	RxMagnetURI         string = "^magnet:\\?xt=urn:[a-zA-Z0-9]+:[a-zA-Z0-9]{32,40}&dn=.+&tr=.+$"
    36  	RxLatitude          string = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
    37  	RxLongitude         string = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
    38  	RxDNSName           string = `^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$`
    39  	RxIP                string = `(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))`
    40  	RxFullURL           string = `^(?:ftp|tcp|udp|wss?|https?):\/\/[\w\.\/#=?&]+$`
    41  	RxURLSchema         string = `((ftp|tcp|udp|wss?|https?):\/\/)`
    42  	RxURLUsername       string = `(\S+(:\S*)?@)`
    43  	RxURLPath           string = `((\/|\?|#)[^\s]*)`
    44  	RxURLPort           string = `(:(\d{1,5}))`
    45  	RxUrlIP             string = `([1-9]\d?|1\d\d|2[01]\d|22[0-3]|24\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-5]))`
    46  	RxURLSubDomain      string = `((www\.)|([a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])*[a-zA-Z0-9]\.[a-zA-Z0-9]+))`
    47  	RxURL               string = `^` + RxURLSchema + `?` + RxURLUsername + `?` + `((` + RxUrlIP + `|(\[` + RxIP + `\])|(([a-zA-Z0-9]([a-zA-Z0-9-_]+)?[a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*)|(` + RxURLSubDomain + `?))?(([a-zA-Z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-zA-Z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-zA-Z\x{00a1}-\x{ffff}]{1,}))?))\.?` + RxURLPort + `?` + RxURLPath + `?$`
    48  	RxSSN               string = `^\d{3}[- ]?\d{2}[- ]?\d{4}$`
    49  	RxWinPath           string = `^[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$`
    50  	RxUnixPath          string = `^(/[^/\x00]*)+/?$`
    51  	RxSemver            string = "^v?(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(-(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\\+[0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*)?$"
    52  	RxHasLowerCase      string = ".*[[:lower:]]"
    53  	RxHasUpperCase      string = ".*[[:upper:]]"
    54  	RxHasWhitespace     string = ".*[[:space:]]"
    55  	RxHasWhitespaceOnly string = "^[[:space:]]+$"
    56  	RxIMEI              string = "^[0-9a-f]{14}$|^\\d{15}$|^\\d{18}$"
    57  )
    58  
    59  var (
    60  	userRegexp          = regexp.MustCompile("^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+$")
    61  	hostRegexp          = regexp.MustCompile("^[^\\s]+\\.[^\\s]+$")
    62  	userDotRegexp       = regexp.MustCompile("(^[.]{1})|([.]{1}$)|([.]{2,})")
    63  	rxEmail             = regexp.MustCompile(RxEmail)
    64  	rxCreditCard        = regexp.MustCompile(RxCreditCard)
    65  	rxISBN10            = regexp.MustCompile(RxISBN10)
    66  	rxISBN13            = regexp.MustCompile(RxISBN13)
    67  	rxUUID3             = regexp.MustCompile(RxUUID3)
    68  	rxUUID4             = regexp.MustCompile(RxUUID4)
    69  	rxUUID5             = regexp.MustCompile(RxUUID5)
    70  	rxUUID              = regexp.MustCompile(RxUUID)
    71  	rxAlpha             = regexp.MustCompile(RxAlpha)
    72  	rxAlphaNumeric      = regexp.MustCompile(RxAlphaNumeric)
    73  	rxAlphaDash         = regexp.MustCompile(RxAlphaDash)
    74  	rxNumeric           = regexp.MustCompile(RxNumeric)
    75  	rxInt               = regexp.MustCompile(RxInt)
    76  	rxFloat             = regexp.MustCompile(RxFloat)
    77  	rxCnMobile          = regexp.MustCompile(RxCnMobile)
    78  	rxHexadecimal       = regexp.MustCompile(RxHexadecimal)
    79  	rxHexColor          = regexp.MustCompile(RxHexColor)
    80  	rxRGBColor          = regexp.MustCompile(RxRGBColor)
    81  	rxASCII             = regexp.MustCompile(RxASCII)
    82  	rxPrintableASCII    = regexp.MustCompile(RxPrintableASCII)
    83  	rxMultiByte         = regexp.MustCompile(RxMultiByte)
    84  	rxFullWidth         = regexp.MustCompile(RxFullWidth)
    85  	rxHalfWidth         = regexp.MustCompile(RxHalfWidth)
    86  	rxBase64            = regexp.MustCompile(RxBase64)
    87  	rxDataURI           = regexp.MustCompile(RxDataURI)
    88  	rxMagnetURI         = regexp.MustCompile(RxMagnetURI)
    89  	rxLatitude          = regexp.MustCompile(RxLatitude)
    90  	rxLongitude         = regexp.MustCompile(RxLongitude)
    91  	rxDNSName           = regexp.MustCompile(RxDNSName)
    92  	rxFullURL           = regexp.MustCompile(RxFullURL)
    93  	rxURLSchema         = regexp.MustCompile(RxURLSchema)
    94  	rxURL               = regexp.MustCompile(RxURL)
    95  	rxSSN               = regexp.MustCompile(RxSSN)
    96  	rxWinPath           = regexp.MustCompile(RxWinPath)
    97  	rxUnixPath          = regexp.MustCompile(RxUnixPath)
    98  	rxSemver            = regexp.MustCompile(RxSemver)
    99  	rxHasLowerCase      = regexp.MustCompile(RxHasLowerCase)
   100  	rxHasUpperCase      = regexp.MustCompile(RxHasUpperCase)
   101  	rxHasWhitespace     = regexp.MustCompile(RxHasWhitespace)
   102  	rxHasWhitespaceOnly = regexp.MustCompile(RxHasWhitespaceOnly)
   103  	rxIMEI              = regexp.MustCompile(RxIMEI)
   104  )