JavaScript / ECMAScript

ISO 3166-1 alpha-2 Country Code in JS

Validate 2-letter ISO 3166-1 alpha-2 country codes (US, GB, FR, JP, etc.) — structural check only.

Try it in the JS tester →

Pattern

regexJS
^[A-Z]{2}$

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^[A-Z]{2}$", "");
const input = "US";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

^[A-Z]{2}$ requires exactly two uppercase letters anchored to the full string. Like the currency-code pattern, this verifies FORMAT not membership — combine with the official list to ensure the code actually exists.

Examples

Input

US

Matches

  • US

Input

GB

Matches

  • GB

Input

USA

No match

Same pattern, other engines

← Back to ISO 3166-1 alpha-2 Country Code overview (all engines)