JS input can only be entered as a number (compatible IE and Firefox) regular

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax digital find firefox javascript multiple online replace

The article has a collection of JS input can only enter a number (compatible with IE and Firefox) is regular, the front two is online to find but seems to not support Ie,firefox regular, and later a very beautiful compatible with multiple browsing the regular method ha.

Only numbers can be entered

<input onkeyup= "value="/value.replace (/["^d]/g") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ') ">
You can only enter a number to lose a decimal point.

<inputōnkeyup= ' if (isNaN (value)) ExecCommand (' Undo ') ' ōnafterpaste= ' if (isNaN (value)) ExecCommand (' Undo ') >
<input name=txt1ōnchange= "if (/d/.test (this.value)) {alert (' can only enter a number '); this.value= ';} ' >
To see a number of instances that can only be entered
Input can only enter the number of online search is for IE, wrote a generic.
Using a jquery method to determine if IE is not

Isnumber = function (e) {  
    if ($.browser.msie) {  
         if ((Event.keycode >) && (Event.keycode < 58) | |   
              (Event.keycode = = 8) {  
            return true;  
       } else {  
             return false;  
       }  
   } else {  
        if ((E.which >) & & (E.which < 58)) | |   
              (E.which = 8)) {   
            return true;  
       } else {  
            return false;  
        }  
   }  
}   html code

<input type= "text" onkeypress= "Web Effects: Return Isnumber (event);" />&NBSP

Related Article

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.