using system;
using system.text.regularexpressions;
namespace bobomousecom.crm
{
/// <summary>
/// regexlib 的摘要說明。
/// </summary>
public class regexlib
{
public regexlib()
{
//
// todo: 在此處添加構造函數邏輯
//
}
//搜索輸入字符串并返回所有 href=“...”值
string dumphrefs(string inputstring)
{
regex r;
match m;
r = new regex("href//s*=//s*(?:/"(?<1>[^/"]*)/"|(?<1>//s+))",
regexoptions.ignorecase|regexoptions.compiled);
for (m = r.match(inputstring); m.success; m = m.nextmatch())
{
return("found href " + m.groups[1]);
}
}
//驗證email地址
bool isvalidemail(string strin)
{
// return true if strin is in valid e-mail format.
return regex.ismatch(strin, @"^([/w-/.]+)@((/[[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3}/.)|(([/w-]+/.)+))([a-za-z]{2,4}|[0-9]{1,3})(/]?)$");
}
//dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。
string mdytodmy(string input)
{
return regex.replace(input,"http://b(?//d{1,2})/(?//d{1,2})/(?//d{2,4})//b","${day}-${month}-${year}");
}
//驗證是否為小數
bool isvaliddecimal(string strin)
{
return regex.ismatch(strin,@"[0]./d{1,2}|[1]");
}
//驗證是否為電話號碼
bool isvalidtel(string strin)
{
return regex.ismatch(strin,@"(/d+-)?(/d{4}-?/d{7}|/d{3}-?/d{8}|^/d{7,8})(-/d+)?");
}
//驗證年月日
bool isvaliddate(string strin)
{
return regex.ismatch(strin,@"^2/d{3}-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|[1-2]/d|3[0-1])(?:0?[1-9]|1/d|2[0-3]):(?:0?[1-9]|[1-5]/d):(?:0?[1-9]|[1-5]/d)$");
}
//驗證后綴名
bool isvalidpostfix(string strin)
{
return regex.ismatch(strin,@"/.(?i:gif|jpg)$");
}
//驗證字符是否在4至12之間
bool isvalidbyte(string strin)
{
return regex.ismatch(strin,@"^[a-z]{4,12}$");
}
//驗證ip
bool isvalidip(string strin)
{
return regex.ismatch(strin,@"^(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])$");
}
}
}