您的位置:首页 > 其它

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);

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: