text field - inputting numbers only

hey I am looking for a way to input numbers to a text field - or any other way do the following:

there's a place where a player can click and input a number. from between 0-300

the field will obviously have to ignore any letters entered.

Off the top of my head, something like this should do it, where you could change int to float all three times if you didn't want integer values:

var num : int = 0;

function OnGUI()
{
    var text = GUI.TextField(Rect(50, 50, 200, 50), num.ToString());
    var temp : int = 0;
    if (int.TryParse(text, temp))
    {
        num = Mathf.Clamp(0, temp);
    }
    else if (text == "") num = 0;
}