数字 邮件 电话 传真 邮政编码 地址验证代码
#region 验证输入字符串为数字
/// <summary>
/// 验证输入字符串为数字
/// </summary>
/// <param name="p_str_num">输入字符</param>
/// <returns>返回一个bool类型的值</returns>
public bool validatenum(string p_str_num)
{
return regex.ismatch(p_str_num, "^[0-9]*$");
}
#endregion#region 验证输入字符串为电话号码
/// <summary>
/// 验证输入字符串为电话号码
/// </summary>
/// <param name="p_str_phone">输入字符串</param>
/// <returns>返回一个bool类型的值</returns>
public bool validatephone(string p_str_phone)
{
return regex.ismatch(p_str_phone, @"d{3,4}-d{7,8}");
}
#endregion#region 验证输入字符串为传真号码
/// <summary>
/// 验证输入字符串为传真号码
/// </summary>
/// <param name="p_str_fax">输入字符串</param>
/// <returns>返回一个bool类型的值</returns>
public bool validatefax(string p_str_fax)
{
return regex.ismatch(p_str_fax, @"86-d{2,3}-d{7,8}");
}
#endregion#region 验证输入字符串为邮政编码
/// <summary>
/// 验证输入字符串为邮政编码
/// </summary>
/// <param name="p_str_postcode">输入字符串</param>
/// <returns>返回一个bool类型的值</returns>
public bool validatepostcode(string p_str_postcode)
{
return regex.ismatch(p_str_postcode, @"d{6}");
}
#endregion#region 验证输入字符串为e-mail地址
/// <summary>
/// 验证输入字符串为e-mail地址
/// </summary>
/// <param name="p_str_email">输入字符串</param>
/// <returns>返回一个bool类型的值</returns>
public bool validateemail(string p_str_email)
{
return regex.ismatch(p_str_email, @"w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*");
}
#endregion#region 验证输入字符串为网络地址
/// <summary>
/// 验证输入字符串为网络地址
/// </summary>
/// <param name="p_str_naddress">输入字符串</param>
/// <returns>返回一个bool类型的值</returns>
public bool validatenaddress(string p_str_naddress)
{
return regex.ismatch(p_str_naddress, @"http(s)?://([w-]+.)+[w-]+(/[w- ./?%&=]*)?");
}
#endregion#region 自动编号
/// <summary>
/// 自动编号
/// </summary>
/// <param name="p_str_sqlstr">sql语句</param>
/// <param name="p_str_table">数据表名</param>
/// <param name="p_str_tbcolumn">数据表字段</param>
/// <param name="p_str_codeindex">编号前的字符串</param>
/// <param name="p_str_codenum">编号后面的数字</param>
/// <param name="txt">textbox控件名</param>
public void autonum(string p_str_sqlstr,string p_str_table,string p_str_tbcolumn,string p_str_codeindex,string p_str_codenum,textbox txt)
{
string p_str_code = "";
int p_int_code = 0;
dataset myds = boperate.getds(p_str_sqlstr,p_str_table);
if (myds.tables[0].rows.count == 0)
{
txt.text = p_str_codeindex + p_str_codenum;
}
else
{
p_str_code = convert.tostring(myds.tables[0].rows[myds.tables[0].rows.count - 1][p_str_tbcolumn]);
p_int_code = convert.toint32(p_str_code.substring(2, 7)) + 1;
p_str_code = p_str_codeindex + p_int_code.tostring();
txt.text = p_str_code;
}
}
#endregion