i need to validate textbox to accept only integer and not more than 100 i create this fuction but i dont how to resrict numbers to be lesss than 100 only

<script type="text/javascript">
<!--
function checkNum(number)
{
if (isNaN(number.value) )
  {
    alert(number.value + " is not a number. Please re-enter.");
    number.focus();
    number.select();
  }
  return;
}

Try this demo:

<html>
<head>
<title></title>
<script type="text/javascript">
<!--
var number = new RegExp(/[0-9]{1,2}/) || /[0-9]{1,2}/; // This will prevent the user from entering non-numeric values on the field -
// and this will also validates on two digits values, so it can only be from 0-99

function checkNum( form ) {
   if (( form ) && (!number.test( form.num.value))) {
      try {
         form.num.focus();
         alert("Invalid entries, this field can only contain digits from 0 through 99");
          return false; 
      } catch( e ) { }
   } return true;
}

//-->
</script>
</head>
<body>
<form action="#" onsubmit="return checkNum(this);">
<div>
<label for="num">Enter a number: <input type="text" id="num" name="num" value="" size="4" /></label>
<input type="submit" id="btn" name="btn" value="Enter" />
</div>
</form>

</body>
</html>

I'm sorry i left something out on line #6.
You'll have to change that pattern with this one var number = new RegExp(/^[0-9]{2}$/) || /^[0-9]{2}$/; good day...

hi
i cant use these reg expression
ana i want to stick to its isnan can i do that or not

Here you have it:

<html>
<head>
<title></title>
<script type="text/javascript">
<!--
var number;
function checkNum( form ) {
   number = new Number( form.num.value ) || parseInt( form.num.value );
   if (( form ) && ( isNaN( form.num.value )) || ( form.num.value.length < 1 )) {
      form.num.focus();
      form.num.select();
      alert( "\"" + form.num.value + "\" is not a number. Please re-enter."); 
      return false;
   } else {
        if (( form ) && ( number > 100 )) {
        alert("Number must be lower than 100!");
           return false; 
        }
        else {
           alert("This number is valid: " + number);
        }
    } return true;
}
//-->
</script>
</head>
<form action="#" onsubmit="return checkNum(this);">
<div>
<label for="num">Enter a number: <input type="text" id="num" name="num" size="3" maxlength="3" /></label> 
<input type="submit" id="btn" name="btn" value="Enter" />
</div>
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.