Check value of a field

If I want to write a code to do a validity check for a field, what should I do?
Is there a guide to consult?