Regex UK Company Number

The rules are this by example
SC01234567, SC12345678  are valid
1234567 is good
01234567 is not valid

Greater than 8 numbers is not valid,
Less than 7 characters is not valid.  
Only the prefix SC are valid characters plus 8 numeric
The company number has eight numbers and where the SC prefix is not used any leading zero is removed

I have got to this point but I am struggling to make each half of the or mutally exclusive.


Question/Request: Each half works fine but I would ideally like them apply the rules above properly.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Your pattern is almost there, I think. You simply need to adjust your bounding. Right now, you've got the "start of string" ( ^ ) only on the latter part. I think you need that for the whole pattern, as well as an "end of string" ( $ ):


Open in new window

You need to surround the innards with brackets so that the ^ and $ aren't affected by the alternation ( | ).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlyantoAuthor Commented:
käµfm³d 👽Commented:

Actually, I would also change the [^0] part. That could potentially accept letters or other symbols as valid. Just use a numeric range that excludes 0:



Open in new window

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

AlyantoAuthor Commented:
Many thanks for your help,
AlyantoAuthor Commented:
Even better, again thank you
AlyantoAuthor Commented:
Conclusion of, and working UK & NI Companies Registration Format

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.