Files
gf/g/net/gipv6/gipv6.go

17 lines
788 B
Go
Raw Normal View History

2017-12-29 16:03:30 +08:00
// Copyright 2017 gf Author(https://gitee.com/johng/gf). 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://gitee.com/johng/gf.
2018-01-03 11:04:47 +08:00
// IPv6
2017-12-29 15:42:42 +08:00
package gipv6
2018-07-11 17:06:47 +08:00
import "gitee.com/johng/gf/g/util/gregex"
2017-12-29 15:42:42 +08:00
// 判断所给地址是否是一个IPv6地址
func Validate(ip string) bool {
2018-07-11 17:06:47 +08:00
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)
2017-12-29 15:42:42 +08:00
}