using System;
using System.Text.RegularExpressions;
class Program
{
static void Main(string[] args)
{
string ssNum = @"\d{3}-\d{2}-\d{4}";
Console.WriteLine (Regex.IsMatch ("111-11-1111", ssNum));
string phone = @"(?x)
( \d{3}[-\s] | \(\d{3}\)\s? )
\d{3}[-\s]?
\d{4}";
Console.WriteLine (Regex.IsMatch ("111-111-1111",phone));
Console.WriteLine (Regex.IsMatch ("(111) 111-1111", phone));
}
}
The output:
True
True
True
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |