using System;

namespace Regexlib
{

/**//// /// Class 的摘要说明。

public class Regexlib
{

public Regexlib()
{
// // TODO: 在此处添加构造函数逻辑 //
}
//搜索输入字符串并返回所有 href=“
”值

string DumpHrefs(String inputString)
{
Regex r;
Match m;
r = new Regex("href\\s*=\\s*(?:\"(?<>[^\"]*)\"|(?<>\\S+))",
RegexOptions.IgnoreCase|RegexOptions.Compiled);
for (m = r.Match(inputString);

m.Success; m = m.NextMatch())
{
Return("Found href " + m.Groups[]);
}
}
//验证Email地址

bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{,}\.[0-9]{,}\.[0-9]{,}\.)|(([\w-]+\.)+))([a-zA-Z]{,}|[0-9]{,})(\]?)$");
}
//dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。

string MDYToDMY(String input)
{
return Regex.Replace(input,"\\b(?\\d{,})/(?\\d{,})/(?\\d{,})\\b","${day}-${month}-${year}");
}
//验证是否为小数

bool IsValidDecimal(string strIn)
{
return Regex.IsMatch(strIn,@"[0].\d{,}|[]");
}
//验证是否为电话号码

bool IsValidTel(string strIn)
{
return Regex.IsMatch(strIn,@"(\d+-)?(\d{}-?\d{7}|\d{}-?\d{8}|^\d{7,8})(-\d+)?");
}
//验证年月日

bool IsValidDate(string strIn)
{
return Regex.IsMatch(strIn,@"^\d{}-(?:0?[-9]|[0-])-(?:0?[-9]|[-]\d|[0-])(?:0?[-9]|\d|[0-]):(?:0?[-9]|[-]\d):(?:0?[-9]|[-]\d)$");
}
//验证后缀名

bool IsValidPostfix(string strIn)
{
return Regex.IsMatch(strIn,@"\.(?i:gif|jpg)$");
}
//验证字符是否再至之间

bool IsValidByte(string strIn)
{
return Regex.IsMatch(strIn,@"^[a-z]{,}$");
}
//验证IP

bool IsValidIp(string strIn)
{
return Regex.IsMatch(strIn,@"^(\d{,}|\d\d|[0-]\d|[0-])\.(\d{,}|\d\d|[0-]\d|[0-])\.(\d{,}|\d\d|[0-]\d|[0-])\.(\d{,}|\d\d|[0-]\d|[0-])$");
}
}
}

posted on
2007-02-12 13:51
mbskys
阅读(
94)
评论()
收藏
举报