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?
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

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.