31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using System.Text.RegularExpressions;
|
||
|
||
namespace _10_6
|
||
{
|
||
internal class Program
|
||
{
|
||
static void Main(string[] args)
|
||
{
|
||
// 验证中国电话号码
|
||
string pattern = @"(\^(\d{3}\ )|\d{3}-)?\d{8}$";
|
||
Console.WriteLine("请输入字符串(中国电话号码)");
|
||
string s = Console.ReadLine();
|
||
bool b1 = Regex.IsMatch(s, pattern);
|
||
Console.WriteLine("{0}是有效的中国电话号码吗? {1}", s, b1);
|
||
// 验证邮政编码
|
||
pattern = @"^\d{6}$";
|
||
Console.WriteLine("请输入字符串(邮政编码)");
|
||
s = Console.ReadLine();
|
||
bool b2 = Regex.IsMatch(s, pattern);
|
||
Console.WriteLine("{0}是有效的邮政编码吗? {1}", s, b2);
|
||
// 有效URL地址
|
||
pattern = @"^http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$";
|
||
Console.WriteLine("请输入字符串(URL地址)");
|
||
s = Console.ReadLine();
|
||
bool b3 = Regex.IsMatch(s, pattern);
|
||
Console.WriteLine("{0}是有效的URL地址吗? {1}", s, b3);
|
||
Console.ReadLine();
|
||
}
|
||
}
|
||
}
|