Okay, here we are. The words I found on the internet a lot of restrictions on the text box is not satisfactory, so had to do their own hands-on practice, the practice of truth, this sentence is correct.
Copy Code code as follows:
function Chkprice (obj) {
Obj.value = Obj.value.replace (/[^\d.) /g, "");
You must ensure that the first digit is not the number.
Obj.value = Obj.value.replace (/^\./g, "");
Ensure that only one is present. and not multiple.
Obj.value = Obj.value.replace (/\.{ 2,}/g, ".");
Guaranteed. Occurs only once, and cannot appear more than two times
Obj.value = Obj.value.replace (".", "$#$"). Replace (/\./g, ""). Replace ("$#$", ".");
}
function Chklast (obj) {
If there's an illegal character, intercept it.
if (Obj.value.substr (obj.value.length-1), 1) = = '. ')
Obj.value = Obj.value.substr (0, (obj.value.length-1));
}
Below is the text box you want to call:
Copy Code code as follows:
<input type= "text" name= "Txtfee id=" Txtfee "class=" common "onkeyup=" chkprice (this); "Onblur=" chklast (This) Onpaste= "Javascript:return false;" />
last this: onpaste= "javascript:return false;" To disable the right mouse button "Paste" menu, you can prevent the right mouse button or Ctrl + V paste illegal data, hehe.
above this JS I only in IE8 environment test, if you reader have any ideas or questions, please leave a message.