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

21번째 줄: 21번째 줄:


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

2023년 4월 8일 (토) 12:09 판

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("example.com"))
	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 }}