Home > DeveloperSection > Forums > What is better solution for validate form TextBoxs value?
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    September-23-2013 5:03 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 515  View(s)
Rate this:

In my system has many forms for insert and edit database registers

But before to save date in database, I need validate any camp, validate it values is empty or not, validate TextBox.Text lenght, etc...

I validated they with many many if's

if (tbName.Text.Equals("")) { }

if (tbPass.Password.Equals("")) { }

if (tbEmail.Text.Equals("")) { }

if (tbTelephone.Text.Equals("")) { }

if (tbNome.Text.Length < 4) { }

if (tbPass.Password.Length < 5) { }

if (!tbEmail.Text.Contains('@')) { }

but it is very no efficiency and I don't know any other solution for this

What solution is usual for this?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-23-2013 7:02 AM

Hi Ankita,

This is by hand so it will have some syntax errors

You will probably also want to implement iNotifyPropertyChanged

Then Validation

public Class ValidatedText

{

    private string vText;

    private bool valid = true;

    Int23 maxLen = 0;

    public bool Valid

    {  

       get { return valid; }

       set

       { 

          if (valid == value) return;

          valid = value;

       }

    }

    public string Vtext

    { 

       get { return vText; }

       set

       { 

          if (vText == value) return;

          if (value.Len < 0)

          {

              Valid = false;

              return;

          }

          // do additional validation here

          vText = value;

       }

   }

   public ValidatedText (string VText; Int32 MaxLen)

   {   vText = Vtext; maxLen - MaxLen;   }

}


Don't want to miss updates? Please click the below button!

Follow MindStick