Determines whether a number is entered in the input box

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en"
<TITLE> New Document </title>
<meta name= "Generator" content= "EditPlus";
<meta name= "Author" content= ""
<meta name= "Keywords" content= "",
<meta name= "Description" content= "";
<script>
Var i=0;//i indicates that the number of
function Checknum (obj) {

//Can be judged no more than 6-bit
if (i==6) {
alert ("Sorry! The number you entered is more than six digits ");
return false;
}
if (i==0) {
if (event.keycode== "0". charCodeAt (0)) {
Alert ("The first cannot be 0, please re-enter!") ");
return false;
}
}
/*if (event.keycode<48| | event.keycode>57) {
Alert ("You are not entering a number, please re-enter!");
return flase;
}*/
//If we can't remember 0->48,9->57, it can be as follows:

//Determine if the input is a number
if (event.keycode< ' 0 '. charCodeAt (0) | | Event.keycode> ' 9 '. charCodeAt (0) {
Alert ("You are not entering a number, please re-enter!");
return false;
//event.returnvalue=false;//This is limited to IE in
}else{
i++;
}
}
</script>

<BODY>
<!--When an event receives a false return value, it indicates that the behavior is discarded--
Please enter a six-digit number: <input type= "text" id= "Pagenow" onkeydown= "return Checknum (This)"/><!--Note that there will be a return value--
</BODY>
</HTML>

<!--

Note: The disadvantage here is that when you think you've lost a mistake, you want to delete the number you entered earlier.

-

Determines whether a number is entered in the input box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.