Last active
February 4, 2024 02:12
-
-
Save rob-murray/01d43581114a6b319034732bcbda29e1 to your computer and use it in GitHub Desktop.
A regex to check UK Company numbers - ie the reference assigned to companies in the UK via Companies House
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/^((AC|ZC|FC|GE|LP|OC|SE|SA|SZ|SF|GS|SL|SO|SC|ES|NA|NZ|NF|GN|NL|NC|R0|NI|EN|\d{2}|SG|FE)\d{5}(\d|C|R))|((RS|SO)\d{3}(\d{3}|\d{2}[WSRCZF]|\d(FI|RS|SA|IP|US|EN|AS)|CUS))|((NI|SL)\d{5}[\dA])|(OC(([\dP]{5}[CWERTB])|([\dP]{4}(OC|CU))))$/ |
Had another go at it:
/^(((AC|CE|CS|FC|FE|GE|GS|IC|LP|NC|NF|NI|NL|NO|NP|OC|OE|PC|R0|RC|SA|SC|SE|SF|SG|SI|SL|SO|SR|SZ|ZC|\d{2})\d{6})|((IP|SP|RS)[A-Z\d]{6})|(SL\d{5}[\dA]))$/;
The rules around registered societies (starting with IP|SP|RS
prefix) could probably be tightened up, this is a more permissive regex, matches all the company numbers in the bulk CSV file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This page has description for PC prefix, but the provided regex does not include it.
In addition, in the official documentation SI prefix listed in the section with prefixes for companies with no available data (only name is available).