Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Validating UUIDs with uuid

validate tells you whether a string is a UUID at all, and version tells you which RFC version it is.

All uuid examples uuid: usage and stats

Validating UUIDs with uuid: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. Check strings with validate(). The loop runs validate on each sample and prints true or false. Only valid strings are passed on to version. [1]
  2. Accept one version only. uuidValidateV4 combines both calls, so a valid v1 UUID is rejected while v4 UUIDs pass. [1]
  3. NIL, MAX and errors. The NIL and MAX constants are valid and report versions 0 and 15. Calling version on a string that is not a UUID throws a TypeError. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import { validate, version, NIL, MAX, v4, v7 } from 'uuid'

const samples = {
  'not a UUID': 'not a UUID',
  'v1 sample': 'd9428888-122b-11e1-b85c-61cd3cbb3210',
  'v4 sample': '109156be-c4fb-41ea-b1b4-efe1671c5836',
  'fresh v7': v7(),
  'NIL': NIL,
  'MAX': MAX,
}

// validate() first, then version() only on valid strings
for (const [label, str] of Object.entries(samples)) {
  const ok = validate(str)
  console.log(`${label}: valid=${ok}` + (ok ? `, version=${version(str)}` : ''))
}

// Per-version check: only accept v4 UUIDs
function uuidValidateV4(uuid) {
  return validate(uuid) && version(uuid) === 4
}
console.log('v4 only -> v4 sample:', uuidValidateV4(samples['v4 sample']))
console.log('v4 only -> v1 sample:', uuidValidateV4(samples['v1 sample']))
console.log('v4 only -> new v4():', uuidValidateV4(v4()))

// version() throws on invalid input
try {
  version('nope')
} catch (err) {
  console.log('version("nope") throws:', err.name)
}
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Add your own strings to the samples object and see which ones pass. Code written by AgentGid [1].

Checked Oct 12, 2026: it starts without errors in Chromium with uuid 14.0.3. Needs WebGL.

More uuid examples

Random UUIDs with uuid v4 Time-based UUIDs with uuid v7 Name-based UUIDs with uuid v5 Converting UUIDs to bytes with uuid

Sources

  1. uuid README (GitHub)

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with uuid? Ask AgentGid →