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.58 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.57 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.56 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.55 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.54 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.53 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.52 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.51 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.50 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.49 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.48 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.47 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.46 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.45 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.44 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.43 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.42 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.41 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.40 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.39 tracks/csharp/exercises/phone-number/Example.cs