sharpoint 客户端对象模型之保存数据 手机号码、邮箱验证
2017-01-23 22:22
441 查看
前台代码//此处是layer的关闭方法。(不懂可百度layer,.net前台弹出窗台用到layer)
function closetaskform() {
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
parent.layer.close(index); //再执行关闭
}
protected void PageSubmit(object sender, EventArgs e)
{
PageConfirm();
}
public void PageConfirm()
{
string script = "alert('留言成功');closetaskform();";//closetaskform是前台js的关闭方法,提交成功后关闭弹出页面
if (txt_Name.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入姓名...')", true);
flag = false;
}
if (txt_Phone.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入联系电话...')", true);
flag = false;
}
//11位电话验证
//电信手机号码正则
string dianxin = @"^1[3578][01379]\d{8}$";
Regex dReg = new Regex(dianxin);
//联通手机号正则
string liantong = @"^1[34578][01256]\d{8}$";
Regex tReg = new Regex(liantong);
//移动手机号正则
string yidong = @"^(134[012345678]\d{7}|1[34578][012356789]\d{8})$";
Regex yReg = new Regex(yidong);
//座机
Regex regex = new Regex("^\\(0\\d{2}\\)[- ]?\\d{8}$|^0\\d{2}[- ]?\\d{8}$|^\\(0\\d{3}\\)[- ]?\\d{7}$|^0\\d{3}[- ]?\\d{7}$", RegexOptions.IgnoreCase);
string phone = txt_Phone.Value.Trim();
if (dReg.IsMatch(phone) || tReg.IsMatch(phone) || yReg.IsMatch(phone) || regex.IsMatch(phone))
{
if (flag)
{
flag = true;
}
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入正确的联系电话...')", true);
txt_Phone.Value = "";
flag = false;
}
//邮箱
string str = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex eegex = new Regex(str, RegexOptions.IgnoreCase);
if (eegex.IsMatch(txt_E_Mail.Value.Trim()))
{
if (flag)
{
flag = true;
}
}
else if (txt_E_Mail.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入邮箱地址...')", true);
flag = false;
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入正确的邮箱地址...')", true);
txt_E_Mail.Value = "";
flag = false;
}
if (txt_Content.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入内容...')", true);
flag = false;
}
if (txt_code.Value.ToUpper().Equals(Session["Code"].SafeToString()))
{
if (flag)
{
flag = true;
}
}
else if (txt_code.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入验证码...')", true);
flag = false;
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误,请重新输入...')", true);
txt_code.Value = "";
flag = false;
}
if (flag)
{
ClientContext context = PageHelper.GetClientContext();
List list = context.Web.Lists.GetByTitle("留言板");
ListItemCreationInformation newProdRecord = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem item = list.AddItem(newProdRecord);
item["Name"] = txt_Name.Value;
item["Phone"] = txt_Phone.Value;
item["E-Mail"] = txt_E_Mail.Value;
item["Company"] = txt_Company.Value;
item["Content"] = txt_Content.Value;
item["IsDeal"] = false;
FrontUser fu = UserMassage.GetUserMassage();
//需要修改登录者
if (!string.IsNullOrEmpty(fu.UserNameCookie))
{
item["Title"] = fu.UserName;//当前登录者真实姓名
}
else
{
item["Title"] = "匿名用户";
}
item.Update();
context.ExecuteQuery();
this.Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), script, true);
}
}
function closetaskform() {
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
parent.layer.close(index); //再执行关闭
}
protected void PageSubmit(object sender, EventArgs e)
{
PageConfirm();
}
public void PageConfirm()
{
string script = "alert('留言成功');closetaskform();";//closetaskform是前台js的关闭方法,提交成功后关闭弹出页面
if (txt_Name.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入姓名...')", true);
flag = false;
}
if (txt_Phone.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入联系电话...')", true);
flag = false;
}
//11位电话验证
//电信手机号码正则
string dianxin = @"^1[3578][01379]\d{8}$";
Regex dReg = new Regex(dianxin);
//联通手机号正则
string liantong = @"^1[34578][01256]\d{8}$";
Regex tReg = new Regex(liantong);
//移动手机号正则
string yidong = @"^(134[012345678]\d{7}|1[34578][012356789]\d{8})$";
Regex yReg = new Regex(yidong);
//座机
Regex regex = new Regex("^\\(0\\d{2}\\)[- ]?\\d{8}$|^0\\d{2}[- ]?\\d{8}$|^\\(0\\d{3}\\)[- ]?\\d{7}$|^0\\d{3}[- ]?\\d{7}$", RegexOptions.IgnoreCase);
string phone = txt_Phone.Value.Trim();
if (dReg.IsMatch(phone) || tReg.IsMatch(phone) || yReg.IsMatch(phone) || regex.IsMatch(phone))
{
if (flag)
{
flag = true;
}
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入正确的联系电话...')", true);
txt_Phone.Value = "";
flag = false;
}
//邮箱
string str = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex eegex = new Regex(str, RegexOptions.IgnoreCase);
if (eegex.IsMatch(txt_E_Mail.Value.Trim()))
{
if (flag)
{
flag = true;
}
}
else if (txt_E_Mail.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入邮箱地址...')", true);
flag = false;
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入正确的邮箱地址...')", true);
txt_E_Mail.Value = "";
flag = false;
}
if (txt_Content.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入内容...')", true);
flag = false;
}
if (txt_code.Value.ToUpper().Equals(Session["Code"].SafeToString()))
{
if (flag)
{
flag = true;
}
}
else if (txt_code.Value == "")
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('请输入验证码...')", true);
flag = false;
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误,请重新输入...')", true);
txt_code.Value = "";
flag = false;
}
if (flag)
{
ClientContext context = PageHelper.GetClientContext();
List list = context.Web.Lists.GetByTitle("留言板");
ListItemCreationInformation newProdRecord = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem item = list.AddItem(newProdRecord);
item["Name"] = txt_Name.Value;
item["Phone"] = txt_Phone.Value;
item["E-Mail"] = txt_E_Mail.Value;
item["Company"] = txt_Company.Value;
item["Content"] = txt_Content.Value;
item["IsDeal"] = false;
FrontUser fu = UserMassage.GetUserMassage();
//需要修改登录者
if (!string.IsNullOrEmpty(fu.UserNameCookie))
{
item["Title"] = fu.UserName;//当前登录者真实姓名
}
else
{
item["Title"] = "匿名用户";
}
item.Update();
context.ExecuteQuery();
this.Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), script, true);
}
}
相关文章推荐
- js验证 正则表达式 包含手机号码、座机号码、电子邮箱、密码、姓名、身份证号码等表单数据的验证
- js中验证邮箱,手机号码,网址,图片等各种数据的正则表达式
- 常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期
- ASP用正则验证邮箱地址手机号码电话号码格式
- 常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期
- JS和正则表达式验证手机号码、邮箱等
- 验证邮箱地址和手机号码
- 常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期
- 常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期
- [转]java正则表达式验证手机号码ip,邮箱
- 常用的js验证代码_数字|电话号码|传真|邮箱|手机号码|邮编
- JS验证 数字 电话号码 传真 邮箱 手机号码 邮编 日期
- 常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期
- java正则表达式验证邮箱、IP地址、手机号码
- 常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期
- 常用的js验证数字,电话号码,传真,邮箱,手机号码,邮编,日期
- 邮箱和手机号码正则表达式验证(手机号码支持188)-HTML-XHTML-CSS
- js验证固话与手机号码、邮箱
- 验证邮箱地址和手机号码 .
- java正则表达式验证手机号码ip,邮箱