The sword may be held in any way so long as it is not used as a throwing weapon (see t.16 Holding the Weapon).
However, the conventional way of holding the foil is to grip the hilt between the thumb and forefinger and use the remaining three fingers as aids to control the movement of the blade.
The thumb should be on top and in line with the blade. The pommel should be held against the wrist in the on-guard position. In the on-guard position the sword should be held such that there is a straight line from the elbow, through the thumb to the point. The elevation of the sword is adjusted by bending from the elbow (not the wrist).
As stated, this is the conventional way of holding the sword but it is not mandatory and other methods can be used so long as they do not break the basic FIE rules. The conventional grip is recomended when learning how to fence, until a personal style is developed.