-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
gipv6.go
15 lines (12 loc) · 847 Bytes
/
gipv6.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// Package gipv6 provides useful API for IPv6 address handling.
package gipv6
import "github.com/gogf/gf/v2/text/gregex"
// Validate checks whether given `ip` a valid IPv6 address.
func Validate(ip string) bool {
return gregex.IsMatchString(`^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$|^:((:[\da-fA-F]{1,4}){1,6}|:)$|^[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,5}|:)$|^([\da-fA-F]{1,4}:){2}((:[\da-fA-F]{1,4}){1,4}|:)$|^([\da-fA-F]{1,4}:){3}((:[\da-fA-F]{1,4}){1,3}|:)$|^([\da-fA-F]{1,4}:){4}((:[\da-fA-F]{1,4}){1,2}|:)$|^([\da-fA-F]{1,4}:){5}:([\da-fA-F]{1,4})?$|^([\da-fA-F]{1,4}:){6}:$`, ip)
}