Developer · Validator

Semver validator.

Check a version against the official SemVer 2.0.0 grammar, see its parts, and compare the precedence of two versions. Runs in your browser; nothing is sent anywhere.

Advertisement

Input

MAJOR.MINOR.PATCH, optionally -prerelease and +build. No leading "v".
A second version to compare precedence against.

Result

Enter a version and press Check.

Advertisement

How SemVer 2.0.0 is checked

A version is MAJOR.MINOR.PATCH, optionally followed by a hyphen and a pre-release, and optionally a plus sign and build metadata, for example 1.0.0-alpha.1+build.5. This page tests your text against the exact regular expression published on semver.org.

Leading zeros: MAJOR, MINOR and PATCH are non-negative integers with no leading zeros, so 01.2.3 is invalid and 0.2.3 is fine. The same goes for numeric pre-release identifiers: 1.0.0-01 is invalid, but 1.0.0-0A is valid because 0A is alphanumeric.

Pre-release: one or more dot-separated identifiers made of 0-9A-Za-z-. None may be empty. A pre-release version has lower precedence than the same version without one, so 1.0.0-rc.1 < 1.0.0.

Build metadata: same characters and dot rules, but leading zeros are allowed (1.0.0+001) and it is ignored when comparing, so 1.0.0+a and 1.0.0+b have equal precedence.

Precedence: compare MAJOR, MINOR, then PATCH numerically. If those tie, compare pre-release identifiers left to right: numeric identifiers numerically, others in ASCII order, numeric lower than alphanumeric, and a longer list wins when all earlier identifiers are equal. That gives 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.

Sources: Semantic Versioning 2.0.0 (semver.org), including its suggested regular expression, and the specification text on GitHub (semver/semver), whose items 2, 9, 10 and 11 define the rules above.

Advertisement

Frequently asked questions

Is "v1.2.3" a valid semver?

No. The leading "v" is a common tag convention, not part of the version. Strip it before validating.

Is "1.2" valid?

No. SemVer requires all three numbers. Many package tools accept shorter ranges, but that is a range syntax, not a version.

Does this handle npm ranges like ^1.2.0 or ~1.2?

No. Those are range expressions defined by npm and other tools, not by the SemVer specification. This page validates single versions only.

Why do 1.0.0+a and 1.0.0+b compare as equal?

The spec says build metadata must be ignored when determining precedence. The two are different strings but have the same precedence.

Worked example: 1.4.0-rc.1+build.7 and three near-misses

Enter 1.4.0-rc.1+build.7. The checker splits it into major 1, minor 4, patch 0, pre-release identifiers rc and 1, and build metadata build and 7.

VersionResultWhy
1.4.0-rc.1+build.7ValidMAJOR.MINOR.PATCH with a pre-release and build metadata
01.2.3InvalidMAJOR may not have a leading zero
1.2InvalidSemVer requires all three numbers
1.0.0-rc.1 compared with 1.0.01.0.0-rc.1 is lowerA pre-release has lower precedence than the same release

Next steps: UUID validator, cron expression parser, or JSON validator.

Syntax check only

This tool checks that a string is well-formed SemVer 2.0.0. It cannot tell you whether that release exists, was published, or follows the rules of semantic versioning in practice. Nothing you type is stored or sent anywhere.