We cannot restrict this. what we can do which is closest to this is have only allowed characters and not let user to move away if he entered a wrong value.
1. Set the maxlength of the textbox to 5. (1 extra to accept the - sign)
2. restrict having characters other than numbers and - sign
Here is a small function for that
function AcceptRegExOnly(event, regex)
{
var keyCode = event.which ? event.which : event.keyCode;
var keyPressed = String.fromCharCode(keyCode);
return regex.test(keyPressed);
};
and this is how it can be used
<asp:TextBox ID="TextBox2" runat="server" onkeypress="return AcceptRegExOnly(event, /^[0-9-]$/);" onblur="return validateOnBlur(this);" MaxLength="5"></asp:TextBox><br />
3. Now validate the value onblur event of this textbox. here is the function for that
function validateOnBlur(sender)
{
var num = Number(sender.value);
if(num < -4713 || num > 9999)
{
alert('invalid value');
sender.focus();
return false;
}
return true;
}