Since you refuse to provide more details, I'll just give you a general idea.
Match the format first using a regular expression, e.g.
- /^\d{1,2}\:\d{2}\:\d{2}(\s?(AM|PM))?$/i
then check each part individually for correctness, e.g. that hours is between 0 and 12, that minutes are between 00 and 59 and so on.