I have used the following in the past.
/// <summary>
/// Override Validation to check to see if our list already contains an item with the same value
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public override string GetValidatedString(object value)
{
// Get Current List
SPList thisList = ParentList;
SPQuery keywordQuery = new SPQuery();
// Check to see if the current field contains the value entered into field
keywordQuery.Query = string.Format("<Where>" +
"<Eq>" +
"<FieldRef Name='{1}' />" +
"<Value Type='Text'>{0}</Value>" +
"</Eq>" +
"</Where>", value, InternalName);
SPListItemCollection liKeywords = thisList.GetItems(keywordQuery);
// Will return greater than 0 if it finds the value in the list
if (liKeywords.Count > 0)
{
// checks to see if the list item is being updated, if it is the same finds the same ID as the one being Validated
if (liKeywords[0].ID != SPContext.Current.ItemId)
{
// Show error message
throw new SPFieldValidationException(string.Format("An item called '{0}' already exists", value));
}
}
// return entered value if unique
return base.GetValidatedString(value);
}
HTH Phill