REGEXVAULTv2.0
Localization/Phone Numbers
Verified Safe

UK Phone Number Regex for Go

/^(?:\+44|0)(?:\s|-)?(?:[1-9][0-9]{1,4})(?:\s|-)?(?:[0-9]{3,4})(?:\s|-)?(?:[0-9]{3,4})$/

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching uk phone number, ported and verified for Go. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// UK Phone Number
// ReDoS-safe | RegexVault — Localization > Phone Numbers

package validation

import "regexp"

var ukPhoneNumberRe = regexp.MustCompile(`^(?:\+44|0)(?:\s|-)?(?:[1-9][0-9]{1,4})(?:\s|-)?(?:[0-9]{3,4})(?:\s|-)?(?:[0-9]{3,4})$`)

func ValidateUkPhoneNumber(s string) bool {
    return ukPhoneNumberRe.MatchString(s)
}

// Example
// fmt.Println(ValidateUkPhoneNumber("+44 20 7946 0958")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
+44 20 7946 0958+1 20 7946 0958
020 7946 095844 20 7946 0958
+447911123456+44 (0) 20 7946
07911 123456
0800 123 456
020-7946-095

When to use this pattern

This pattern is drawn from the Localization > Phone Numbers category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

UK numbers vary in length depending on area code — London has an 8-digit local number, while rural areas may have 7 or even 6. This variability makes regex validation approximate at best.

Technical Notes

UK uses a complex numbering plan. 020 = London, 0161 = Manchester, 07xxx = mobile, 0800 = freephone, 01xxx/02xxx = geographic. The (0) is sometimes shown in international format (+44 (0)20...) but not dialed.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern