jquery-Qualified text boxes can only enter numbers-integers and decimal _jquery

Source: Internet
Author: User
Copy Code code as follows:

$ (function () {
Text boxes can only enter numbers (excluding decimals) and screen input and paste
$.fn.integer= function () {
$ (this). CSS ("Ime-mode", "disabled");
This.bind ("KeyPress", function (e) {
var code = (E.keycode E.keycode:e.which); Compatible with Firefox IE
if (!$.browser.msie&& (e.keycode==0x8)) {//Firefox can not use the BACKSPACE key
return;
}
Return code >= && code<= 57;
});
This.bind ("Paste", function () {
return false;
});
This.bind ("KeyUp", function () {
if (/(^0+)/.test (this.value)) {
This.value = This.value.replace (/^0*/, ");
}
});
};

Text boxes can only enter numbers (including decimals) and screen input and paste
$.fn.number= function () {
$ (this). CSS ("Ime-mode", "disabled");
This.bind ("KeyPress", function (e) {
var code = (E.keycode E.keycode:e.which); Compatible with Firefox IE
if (!$.browser.msie&& (e.keycode==0x8)) {//Firefox can not use the BACKSPACE key
return;
}
if (This.value.indexOf (".") ==-1) {
Return (Code >= && code<= 57) | | (code==46);
}else{
Return code >= && code<= 57
}
});
This.bind ("Paste", function () {
return false;
});
This.bind ("KeyUp", function () {
if (this.value.slice (0,1) = = ".") {
This.value = "";
}
});
This.bind ("Blur", function () {
if (This.value.slice (-1) = = ".") {
This.value = This.value.slice (0,this.value.length-1);
}
});
};
});

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.