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.78 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.77 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.76 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.75 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.74 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.73 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.72 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.71 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.70 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.69 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.68 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.67 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.66 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.65 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.64 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.63 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.62 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.61 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.60 tracks/csharp/exercises/phone-number/Example.cs
trackler-2.2.1.59 tracks/csharp/exercises/phone-number/Example.cs