Only specific numbers in edit box
问题 I would like that user could write only numbers from 1 to 49 in edit box. I know how to exclude letters and has possibility to put only numbers but I can't limit it to specific numbers (e.g from 1 to 49 - like in lottery game). I added KeyDown event to edit box and put this code: if not (KeyChar in ['1'..'9']) then begin ShowMessage('Invalid character'); KeyChar := #0; end; How can I modify it? 回答1: Following David's advice, a pattern I often use looks something like this : function