Sha256: 6159a0926cbedabe6b9fed00139de05b03fc6282ce26e98cd6665a6c0d8be747
Contents?: true
Size: 606 Bytes
Versions: 165
Compression:
Stored size: 606 Bytes
Contents
using System; using System.Linq; using System.Text.RegularExpressions; public class PhoneNumber { private static readonly Regex phoneNumberFormat = new Regex("^1?([2-9][0-9]{2}[2-9][0-9]{6})$"); public static string Clean(string phoneNumber) { var digits = string.Join(string.Empty, phoneNumber.Where(l => l >= '0' && l <= '9')); var match = phoneNumberFormat.Match(digits); if (match.Success) { return match.Groups[1].ToString(); } else { throw new ArgumentException("invalid phone number"); } } }
Version data entries
165 entries across 165 versions & 1 rubygems