using System;
using System.Web;
using System.IO;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
namespace MyOraComm
{
/// <summary>
/// FuncTion 的摘要說明。
/// </summary>
public class Function
{
public Function()
{
//
// TODO: 在此處添加構造函數邏輯
//
}
// ====== ==============================================================================
//=========================前臺輸出語句方法================================
//=======================================================================================
#region 彈出javascript對話框,是否返回或結束。
public void WriteMessage(string strMsg,bool Back,bool End)
{
HttpContext Context=HttpContext.Current;
strMsg=strMsg.Replace("'","");
strMsg=strMsg.Replace("/r/n","");
if(strMsg!=""&&strMsg!=null)
Context.Response.Write("<script language=javascript>alert('"+strMsg+"');</script>");
if(Back)
Context.Response.Write("<script language=javascript>history.back();</script>");
if(End)
Context.Response.End();
}
#endregion
#region 寫javascript語句內容,<script language=javascript></script>已經寫好。
public void WriteJavaScript(string strJavaScript)
{
HttpContext Context=HttpContext.Current;
Context.Response.Write("<script language=javascript>"+strJavaScript+"</script>");
}
#endregion
#region 關閉當前頁面
public void CloseWindow()
{
HttpContext Context=HttpContext.Current;
Context.Response.Write("<script language=javascript>window.close();</script>");
Context.Response.End();
}
#endregion
//====================================================================================
//=========================使用正則表達式寫的驗證類方法================================
//=====================================================================================
#region 用正則表達式實現.驗證輸入是否是數字
public bool IsValidNumer(string str)
{
System.Text.RegularExpressions.Regex reg1
= new System.Text.RegularExpressions.Regex(@"^[-]?/d+[.]?/d*$");
return reg1.IsMatch(str);
}
#endregion
#region 驗證是否為小數
public bool IsValidDecimal(string str)
{
return Regex.IsMatch(str,@"[0]./d{1,2}|[1]");
}
#endregion
#region 驗證Email地址
public 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})(/]?)$");
}
#endregion
#region dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。
public string MDYToDMY(String input)
{
return Regex.Replace(input,"http://b(?//d{1,2})/(?//d{1,2})/(?//d{2,4})//b","${day}-${month}-${year}");
}
#endregion
#region 驗證是否為電話號碼
public bool IsValidTelNum(string strIn)
{
return Regex.IsMatch(strIn,@"(/d+-)?(/d{4}-?/d{7}|/d{3}-?/d{8}|^/d{7,8})(-/d+)?");
}
#endregion
#region 驗證年月日
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)$");
}
#endregion
#region 驗證后綴名
bool IsValidPostfix(string strIn)
{
return Regex.IsMatch(strIn,@"/.(?i:gif|jpg)$");
}
#endregion
#region 驗證字符是否在4至12之間
bool IsValidByte(string strIn)
{
return Regex.IsMatch(strIn,@"^[a-z]{4,12}$");
}
#endregion
#region 驗證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])$");
}
#endregion
}
}