Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Agenda of Contacts

$
0
0

Hello,

I have to make an agenda of contacts. First I put my data(name,surname,mobile,..) in textboxes and after I save them in a datagridview. I have to save some checks (for example mobile must have only 10 digits and only digits) and if all of my checks are correct then to save them in the datagridview. Here is my code which send them independently the checks. What else I need in order to send them correctly in the datagridview.

I have a button with name button 1 which send the data in datagridview:

         

 private void button1_Click(object sender, EventArgs e)
        {

            CheckPhoneNumber();
            checkEmail();



           try
            {

                contacts c = new contacts(textBox1.Text, textBox2.Text, long.Parse(textBox3.Text), textBox4.Text, dateTimePicker1.Text);
                list.Add(c);
                updateViews();
                button8_Click(sender, e);

            }
            catch
            {

            }




        }

And here are my checks:

 private void CheckPhoneNumber()
        {
            phonevalue = textBox3.Text;


            if (phonevalue.All(Char.IsDigit))  //
            {
                if (phonevalue.Length < 10)  //If digits are less than 10             {
                    MessageBox.Show("Must contain 10 digits");
                }
                
            }
            else //If input is characters
            {
                if (phonevalue.Length < 10)
                {
                    MessageBox.Show("Put 10 digits");
                }
                else
                {
                    MessageBox.Show("It must contain only numbers");
                }

            }
        }

        private void checkEmail()
        {

            string email = textBox4.Text;

            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");

            Match match = regex.Match(email);

            if (match.Success)
            {
                label6.Visible = true;
                label6.Text = "Email is valid";
                
            }
            else
            {
                label6.Visible = true;
                label6.Text = "Email is invalid";
            }

        }

 Thank you in advance.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>