mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 04:53:11 +00:00
25 lines
754 B
C#
25 lines
754 B
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
public static class VendorPhoneNormalizer
|
|
{
|
|
public static readonly Regex NorthAmericanPhoneRegex = new(
|
|
@"^\(\d{3}\) \d{3}-\d{4}$",
|
|
RegexOptions.Compiled);
|
|
|
|
public static string? NormalizeToCanonical(string? value)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
return null;
|
|
|
|
var digits = new string(value.Where(char.IsDigit).ToArray());
|
|
if (digits.Length == 11 && digits.StartsWith('1'))
|
|
digits = digits[1..];
|
|
|
|
return digits.Length == 10
|
|
? $"({digits[..3]}) {digits[3..6]}-{digits[6..]}"
|
|
: value;
|
|
}
|
|
}
|
|
}
|