look at masks to do simple restriction.
secondly I have used on update event which if i remember correctly fires on each key stroke to as opposed to modifed event (may be the other way round) and then check if the last entered character satisfys your criteria.
Done both in stellatools if you care to look up.