Example #1
0
 //Validating Phone number with regex
 private void PhoneText_Validating(object sender, CancelEventArgs e)
 {
     if (!Regex.Match(PhoneText.Text, "^[0-9-()/]*$").Success)
     {
         MessageBox.Show("Not a valid phone number!");
         PhoneText.Focus();
     }
     ;
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            password = ConfirmPassword.Text;
            //string encryptedPassword = Encrypt(password);
            int    phoneNumber = PhoneText.Text.Length;
            int    passLength  = PasswordText.Text.Length;
            string gender      = "";

            if (MaleButton.Checked)
            {
                gender = MaleButton.Text;
            }
            if (FemaleButton.Checked)
            {
                gender = FemaleButton.Text;
            }
            //this.Hide();
            //Home ss = new Home();
            // ss.Show();

            //check field empty or not
            if (string.IsNullOrEmpty(NameTextBox.Text) == true)
            {
                MessageBox.Show("Please enter First Name");
                NameTextBox.Focus();
            }
            else if (string.IsNullOrEmpty(LastNameTextBox.Text) == true)
            {
                MessageBox.Show("Please enter Last Name");
                LastNameTextBox.Focus();
            }
            else if (string.IsNullOrEmpty(EmailTextBox.Text) == true)
            {
                MessageBox.Show("Please enter Email");
                EmailTextBox.Focus();
            }
            else if (Regex.IsMatch(EmailTextBox.Text, emailValStr) == false)
            {
                MessageBox.Show("Invalid email!!");
                EmailTextBox.Focus();
            }

            else if (string.IsNullOrEmpty(StudentIDTextBox.Text) == true)
            {
                MessageBox.Show("Please enter your ID");
                StudentIDTextBox.Focus();
            }
            else if (string.IsNullOrEmpty(PhoneText.Text) == true)
            {
                MessageBox.Show("Please enter Phone Number");
                PhoneText.Focus();
            }

            else if (phoneNumber != 11)
            {
                MessageBox.Show("Please enter valid phone number");
                PhoneText.Focus();
            }
            else if (string.IsNullOrEmpty(gender) == true)
            {
                MessageBox.Show("Please select gender");
                ConfirmPassword.Focus();
            }
            else if (string.IsNullOrEmpty(PasswordText.Text) == true)
            {
                MessageBox.Show("Please type Password");
                PasswordText.Focus();
            }
            else if (passLength <= 8)
            {
                MessageBox.Show(Convert.ToString(passLength));
                MessageBox.Show("Your password should contain minimum 8 characters or numbers");
                PasswordText.Focus();
            }
            else if (string.IsNullOrEmpty(ConfirmPassword.Text) == true)
            {
                MessageBox.Show("Please type Password again");
                ConfirmPassword.Focus();
            }
            else if (PasswordText.Text != ConfirmPassword.Text)
            {
                MessageBox.Show("You typed the wrond password");
                PasswordText.Focus();
            }

            else
            {
                // conn.ConnectionString = @"Data Source=LAPTOP-UDPCMQEF;Initial Catalog=LibraryManagementSystem;Integrated Security=True";
                //  conn.Open();


                SqlCommand cmd = new SqlCommand("insert into Person" + "(first_name,last_name,password,email,student_id,gender,contact_no) values (@first_name,@last_name,aes_encrypt(@password, 'key'),@email,@student_id,@gender,@contact_no)", connDB.getConn());
                cmd.Parameters.AddWithValue("@first_name", NameTextBox.Text);
                cmd.Parameters.AddWithValue("@last_name", LastNameTextBox.Text);
                cmd.Parameters.AddWithValue("@email", EmailTextBox.Text);
                cmd.Parameters.AddWithValue("@student_id", StudentIDTextBox.Text);
                cmd.Parameters.AddWithValue("@gender", gender);
                cmd.Parameters.AddWithValue("@contact_no", PhoneText.Text);
                cmd.Parameters.AddWithValue("@password", password);
                cmd.ExecuteNonQuery();
                MessageBox.Show("You are registered now");
            }
        }