How to validate UUID v4 in Go?

Regex is expensive. The following approach is ~18x times faster than the regex version.

Use something like https://godoc.org/github.com/google/uuid#Parse instead.

import "github.com/google/uuid"

func IsValidUUID(u string) bool {
    _, err := uuid.Parse(u)
    return err == nil
 }

Leave a Comment