updated the phone regex to enforce strictness

This commit is contained in:
Alfred Kamanda 2025-04-17 14:00:40 +03:00
parent 9fbae0471f
commit bb314d725c
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -9,7 +9,9 @@ import (
// Define the regex patterns as constants // Define the regex patterns as constants
const ( const (
// TODO: This should rather use a phone package to determine whether valid phone number for any region. // TODO: This should rather use a phone package to determine whether valid phone number for any region.
phoneRegex = `^(?:\+254|254|0)?((?:7[0-9]{8})|(?:1[01][0-9]{7}))$` // Kenyan phone numbers: must be exactly 10 digits (07XXXXXXXX or 01XXXXXXXX) when starting with 0
// Or start with 254 / +254 and still follow the same pattern
phoneRegex = `^(?:\+254|254|0)(7\d{8}|1[01]\d{7})$`
) )
// IsValidPhoneNumber checks if the given number is a valid phone number // IsValidPhoneNumber checks if the given number is a valid phone number