Employers - Post Free Jobs
Forum guidelines
AuthorQuestion
How to validate Password textbox C# winfrom
Posted on: 09 Apr 2013
Hi,

I have a change password form, which I would like to check :
        1.it shouldn't be empty or null
        2.txtNewpassword.Text = txtConfimPassword.Text

How to write if statement for those conditions./

Thanks.

AuthorReply
Re: How to validate Password textbox C# winfrom
Posted on: 09 Apr 2013  
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Fetch_multi_in_combobox
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (txtNewpassword.Text == "" || txtConfimPassword.Text == "")
            {
                MessageBox.Show("Please enter values");
                return;
            }
            if (txtConfimPassword.Text != txtNewpassword.Text)
            {
                MessageBox.Show("confirm password not matching with new passsword");
                txtConfimPassword.Focus();
                return;
            }
        }
    }
}


If this post helps you mark it as answer
Thanks

Re: How to validate Password textbox C# winfrom
Posted on: 25 Apr 2013  

Hi Nazhand,

You can use check for null or empty values using string.IsNullOrEmpty method of string class.

     if(string.IsNullOrEmpty(txtNewpassword.Text))
      {
                 MessageBox.Show("Please enter values");
                return;
       }

Thanks, Shankar M
Re: How to validate Password textbox C# winfrom
Posted on: 25 Apr 2013  

hi,

try
string newPassword =  txtNewpassword.Text;
string confirmPassword = txtConfimPassword.Text;
if (!string.IsNullOrEmpty(newPassword) && !string.IsNullOrEmpty(newPassword) && newPassword.Equals(confirmPassword))
{
    //do change password.
}
else
{
    //show the error.
}

hope this will help you.


SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.