Hi Hilmar.
In general, you can put validation code in a TextBox Valid() Event. If a condition is not fulfilled, return .F. to avoid losing the focus.There is one tiny problem with this in VFP 5. This is what we had to say about it in Chapter 6 of
1001 Things You Wanted to Know About Visual FoxProGotcha! Grid's valid fires before the valid of the current controlNotice that when moving from a grid to another object on the form, the grid's Valid fires before the valid of the active cell. This is a bug. Normally you would expect to use the control's Valid method to determine whether that control can lose focus. However, when a control is contained within a grid, there are two levels at which focus operates. First, between the control and other controls that are also within the grid. In this context things behave normally.
Second there is the issue of which form object has focus. This bug will bite you when focus is being moved between the grid and another object. It is, as you would expect, the grid’s Valid method that determines whether the grid can lose focus. However, because the grid’s Valid is called before that of any contained control, a contained control cannot prevent the grid from losing focus even though its own validation has failed.
This can and will allow bad data to be entered into the grid. Fortunately, there is an easy workaround, which ensures that the grid’s Valid explicitly calls and returns the result of any contained control’s validation. So if the text box in the first column of the grid has code in its Valid, this line in the grid's Valid method takes care of the problem:
RETURN This.Column1.Text1.Valid()