data validation

data validation

I was trying to validate a form with the following code:


  1. if (count(Address[Address_Name == input.Address_Name && client_code == input.client_code])  >  0)
  2. {
  3.     alert ("An address with the name already exists for this client. Please enter a new name.");
  4.     cancel submit;
  5. }

But it is not working. Sometime the validation works and throws the alert and sometimes the user can enter the data successfully. I thought it was a really easy validation.

Am I doing something wrong or there is something wrong with my application? The only possible problem I can see in this code is:





  1.  Address[Address_Name == input.Address_Name && client_code == input.client_code]

Can I do something like this? Or I will have to do this:



  1. Address[client_code == input.client_code]
and fetch all the records and inside a loop check for the address name?