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

Version Path
trackler-2.2.1.180 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.179 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.178 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.177 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.176 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.175 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.174 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.173 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.172 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.171 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.170 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.169 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.167 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.166 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.165 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.164 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.163 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.162 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.161 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.160 tracks/csharp/exercises/phone-number/Example.cs