There are a number of existing checkers that work pretty well -
Google[
^] can help you there - but writing your own from scratch is a pretty massive task. There are some
Open source checkers[
^] available which should give you an idea or two however.