How can check some field value existense in the table

In the frontend ,i have a text box which accepts program id .If we gives
value in that , it will get stored in sql database, but before storing
i want to check whether the program id is exist in database. If exist
then we
instruct the user to give another program id. If not then ok to insert.
how can i validate this input?

Thanks in advance.
Prabu J.

On 3 February 2011 10:55, Prabu J. [email protected] wrote:

In the frontend ,i have a text box which accepts program id .If we gives
value in that , it will get stored in sql database, but before storing
i want to check whether the program id is exist in database. If exist
then we
instruct the user to give another program id. If not then ok to insert.
how can i validate this input?

Use validates_uniqueness_of on the field, but also specify a unique
key constraint in the database in order to ensure that a duplicate
value cannot be saved, as validates_uniqueness_of can fail to detect
duplicate values due to race conditions.

Colin