using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.Globalization; using System.Text.RegularExpressions; public class RegexUtilities1 { bool invalid = false; public bool IsValidEmail(string strIn) { invalid = false; if (String.IsNullOrEmpty(strIn)) return false; // Use IdnMapping class to convert Unicode domain names. strIn = Regex.Replace(strIn, @"(@)(.+)$", this.DomainMapper, RegexOptions.None); if (invalid) return false; return Regex.IsMatch(strIn, @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,24}))$", RegexOptions.IgnoreCase); } private string DomainMapper(Match match) { // IdnMapping class with default property values. IdnMapping idn = new IdnMapping(); string domainName = match.Groups[2].Value; try { domainName = idn.GetAscii(domainName); } catch (ArgumentException) { invalid = true; } return match.Groups[1].Value + domainName; } } public partial class Register : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList1.DataSource = Enumerable.Range(8, 4).ToList(); DropDownList1.DataBind(); } Label1.ForeColor = Color.Gray; Label2.ForeColor = Color.Gray; Label3.ForeColor = Color.Gray; Label4.ForeColor = Color.Gray; Label5.ForeColor = Color.Gray; Label6.ForeColor = Color.Gray; Label7.ForeColor = Color.Gray; Label8.ForeColor = Color.Gray; Label10.ForeColor = Color.Gray; } protected void Button1_Click1(object sender, EventArgs e) { if (TextBox1.Text == "" | TextBox2.Text == "" | TextBox3.Text == "" | TextBox4.Text == "" | TextBox5.Text == "" | TextBox7.Text == "" | TextBox8.Text == "") { Label9.ForeColor = Color.Red; Label9.Text = "Пожалуйста, введите все данные. Незаполненные поля помечены красным."; if (TextBox1.Text == "") { Label1.ForeColor = Color.Red; } if (TextBox2.Text == "") { Label2.ForeColor = Color.Red; } if (TextBox3.Text == "") { Label3.ForeColor = Color.Red; } if (TextBox4.Text == "") { Label4.ForeColor = Color.Red; } if (TextBox5.Text == "") { Label5.ForeColor = Color.Red; } if (TextBox8.Text == "") { Label7.ForeColor = Color.Red; } if (TextBox7.Text == "") { Label8.ForeColor = Color.Red; } } else { if (!Regex.IsMatch(TextBox1.Text, "^[А-Яа-я]+$") | !Regex.IsMatch(TextBox2.Text, "^[А-Яа-я]+$") | !Regex.IsMatch(TextBox3.Text, "^[А-Яа-я]+$") | !Regex.IsMatch(TextBox4.Text, "^[А-Яа-я]+$")) { Label9.ForeColor = Color.Red; Label9.Text = "Пожалуйста, введите все данные корректно. Некорректно заполненные поля помечены красным."; if (!Regex.IsMatch(TextBox1.Text, "^[А-Яа-я]+$")) { Label1.ForeColor = Color.Red; } if (!Regex.IsMatch(TextBox2.Text, "^[А-Яа-я]+$")) { Label2.ForeColor = Color.Red; } if (!Regex.IsMatch(TextBox3.Text, "^[А-Яа-я]+$")) { Label3.ForeColor = Color.Red; } if (!Regex.IsMatch(TextBox4.Text, "^[А-Яа-я]+$")) { Label4.ForeColor = Color.Red; } } else { string strIn = TextBox8.Text; RegexUtilities1 util = new RegexUtilities1(); if (!util.IsValidEmail(strIn)) { Label7.ForeColor = Color.Red; Label9.ForeColor = Color.Red; Label9.Text = "Пожалуйста, введите ваш почтовый ящик корректно. Например: ivanivanov@pochta.ru ."; } else { klientDataContext db = new klientDataContext(); List u; u = db.users.ToList(); string str1 = TextBox8.Text.ToLower().Replace(" ", string.Empty); int m = 0; for (int i = 0; i < u.Count; i++) { if (u[i].email == str1) { m = 1; } } if (m == 1) { Label7.ForeColor = Color.Red; Label9.ForeColor = Color.Red; Label9.Text = "Такой почтовый адрес уже зарегистрирован в системе."; } else { if (CheckBox1.Checked == true) { student table = new student(); table.name = TextBox1.Text.ToUpper(); table.midname = TextBox2.Text.ToUpper(); table.surname = TextBox3.Text.ToUpper(); table.school = TextBox5.Text.ToUpper(); table.classof = Convert.ToInt32(DropDownList1.SelectedItem.Value); table.id_stud = (db.student.Count() + 1); table.dateofregistration = DateTime.Today; string c = TextBox4.Text.ToUpper(); List lcity; lcity = db.city.ToList(); string str = c.Replace(" ", string.Empty); int r = 0; for (int i = 0; i < lcity.Count; i++) { if (lcity[i].name_c == str) { r = lcity[i].id_с; } } if (r != 0) { table.city = r; } else { city t2 = new city(); t2.id_с = (db.city.Count() + 1); t2.name_c = str; table.city = (db.city.Count() + 1); db.city.InsertOnSubmit(t2); } db.student.InsertOnSubmit(table); users newu = new users(); newu.password = TextBox7.Text.Replace(" ", string.Empty); newu.email = str1; newu.student = (db.student.Count() + 1); newu.id = (db.users.Count() + 1); db.users.InsertOnSubmit(newu); db.SubmitChanges(); Response.Redirect("Default.aspx"); } else { Label9.ForeColor = Color.Red; Label9.Text = "Ваши данные будут использованы только в качестве статистики, но, к сожалению, без Вашего согласия регистрация невозможна."; } } } } } } }