Archived
1
0
This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SomeLab/CS/lab10/10_6/Program.cs
2026-03-19 19:39:01 +08:00

31 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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();
}
}
}