//对于输入进行验证 //将数据存入数据库 protected void Register_Click(object sender, EventArgs e) { string userNameRegex = @"^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){5,19}$"; if (!Regex.IsMatch(Name.Text.ToString(), userNameRegex)) throw new Exception(); string passwordRegex = @".{5,19}$"; if (!Regex.IsMatch(Password1.Text.ToString(), passwordRegex)) throw new Exception(); if (!Regex.IsMatch(Password2.Text.ToString(), passwordRegex)) throw new Exception(); string mailRegex = @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"; if (!Regex.IsMatch(MailBox.Text.ToString(), mailRegex)) throw new Exception(); StudentInfo student = new StudentInfo(); student.Stu_UserName = Name.Text.ToString().Trim(); student.Stu_Email = MailBox.Text.ToString().Trim(); student.Stu_Validation = "success"; student.Stu_LastLogin = DateTime.Now; student.Stu_RegisteTime = DateTime.Now; student.Stu_Image = "~/Resource/Image/Upload/default.jpg"; if(!Password1.Text.Equals(Password2.Text.Trim())){ throw new Exception(); } student.Stu_Password = Password1.Text.ToString().Trim(); bllStudent.Add(student); Response.Redirect("~/Student/Login.aspx"); }
protected void Submit_Click(object sender, EventArgs e) { if (!Regex.IsMatch(StuNickName.Text.ToString(), @"^\S{2,10}$")) { throw new Exception(); } if (!Regex.IsMatch(StuNickName.Text.ToString(), @"^\S[^\^]+$")) { throw new Exception(); } if (!Regex.IsMatch(StuEmail.Text.ToString(), @"^\S[^\^]+$")) { throw new Exception(); } if (!Regex.IsMatch(StuPassword.Text.ToString(), @"^\S{1,10}$")) { throw new Exception(); } if (!Regex.IsMatch(StuPassword.Text.ToString(), @"^\S[^\^]+$")) { throw new Exception(); } //头像 if (!Regex.IsMatch(StuPassword.Text.ToString(), @"^\d+$")) { throw new Exception(); } string server = Server.MapPath("~/"); string imageName = UploadSupport.GenerateRandom(10) + ".jpg"; string error; if (!UploadSupport.SaveImage(ImageFile, server, imageName, out error)) { return; } StudentInfo student = new StudentInfo(); student.Stu_UserName = StuNickName.Text.ToString(); student.Stu_Password = StuPassword.Text.ToString(); student.Stu_Email = StuEmail.Text.ToString(); //头像 //时长 student.Stu_RegisteTime = DateTime.Now; student.Stu_LastLogin = DateTime.Now; bllStudent.Add(student); Response.Redirect("~/User/UserList.aspx"); }