Is this in a SQL database? If so you can setup a SQL Constraint to do this.