"Go isIP()"의 두 판 사이의 차이

30번째 줄: 30번째 줄:


[[분류: Go]]
[[분류: Go]]
[[분류: import "net"]]
[[분류: Go 패키지 net]]

2023년 4월 7일 (금) 19:30 판

1 개요

Go isIP()
Go validateIP()
package main

import (
	"fmt"
	"net"
)

func isIP(ip string) bool {
	return net.ParseIP(ip) != nil
}

func main() {
	// true
	fmt.Println(isIP("10.40.210.253"))
	fmt.Println(isIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))

	// false
	fmt.Println(isIP("1000.40.210.253"))
	fmt.Println(isIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334:3445"))
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}