Go isIP()

Jmnote (토론 | 기여)님의 2023년 4월 7일 (금) 19:28 판 (새 문서: ==개요== ;Go isIP() ;Go validateIP() <syntaxhighlight lang='go' run> package main import ( "fmt" "net" ) func isIP(ip string) bool { return net.ParseIP(ip) != nil } func main...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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 }}