The limit is an integer.
Copy codeThe Code is as follows: <Head>
<Script language = "javascript" type = "text/javascript">
Var G = document. getElementById;
Function checkNumber (){
Var reg =/^ (? : 0 | [1-9] [0-9]? | 100) $ /;
Var strNumber = G ("txtNumber"). value;
Alert (reg. test (strNumber ))
}
</Script>
</Head>
<Body>
<Input type = "text" value = "" id = "txtNumber" title = "Please enter a number witch between 0 and 100...">
<Button onclick = "checkNumber ();"> CheckNumber </button>
</Body>
</Html>
Restricted to currencyCopy codeThe Code is as follows: <script language = "JavaScript" type = "text/javascript">
<! --
Function checkMoney (obj ){
Var tempValue = obj. value. replace (/(^ \ s +) | (\ s + $)/g ,'');
If (! TempValue) {return ;}
If (/^ -? \ D + (\. \ d + )? $/. Test (tempValue )){
Obj. value = parseFloat (tempValue). toFixed (2 );
} Else {
Alert ('enter a valid currency value! ');
Obj. select ();
Return;
}
}
// -->
</Script>
// Trigger the event
Onblur = "checkMoney (this )"