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.98 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.97 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.96 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.95 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.94 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.93 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.92 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.91 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.90 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.89 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.88 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.87 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.86 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.85 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.84 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.83 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.82 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.81 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.80 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.79 tracks/csharp/exercises/phone-number/Example.cs