Jquery money verification, converted to kilobytes

Source: Internet
Author: User
Function convert (amtstr) {var A, renum = ''; var J = 0; var a1 ='', a2 = '', A3 = ''; vaR tes =/^-/; A = amtstr. replace (/,/g, ""); A =. replace (/[^ -\., 0-9]/g, ""); // Delete invalid character a =. replace (/(^ \ s *) | (\ s * $)/g, ""); // trim if (TES. test (A) a1 = '-'; else a1 = ''; A =. replace (/-/g, ""); if (! = "0" & A. substr (0, 2 )! = "0. ") A =. replace (/^ 0 */g, ""); j =. indexof ('. '); If (j <0) J =. length; a2 =. substr (0, J); a3 =. substr (j); j = 0; for (I = a2.length; I> 3; I = I-3) {renum = "," + a2.substr (I-3, 3) + renum; j ++;} renum = A1 + a2.substr (0, a2.length-J * 3) + renum + A3; return renum ;} /****** convert money *****/function convertmoney () {$ ("[money]"). each (function () {var STR = $ (this ). val (); $ (this ). K Eyup (function (EVT) {STR = $ (this). Val (); EVT = (EVT )? EVT: (window. Event )? Window. Event: "") // compatible with IE and Firefox, get the keyboardevent object var key = EVT. keycode? EVT. keycode: EVT. which; // compatible with IE and Firefox, obtain the key value of the keyboardevent object if (Key >=33 & Key <= 40) {EVT. preventdefault (); EVT. returnvalue = false; return false;} $ (this ). val (convert (STR) ;}); If (STR! = "") {$ (This). Val (convert (STR) ;}}) ;}$ (function (){

Convertmoney ();


});

First introduce the above code, and then add a money attribute to your textbox. The value is any value.
Then you can verify all the money.

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.