The code is as follows:
$("#money").bind ("propertychange",function() {
if(""!=this.value){
var str = this.value.replace(/(^s*)|(s*$)/g, "");
if(this.value != str )
this.value = str;
}
if( isNaN(Number(this.value)))
this.value = this.value.replace(/[D]/,'');
});
JQuery is used here to bind to the onpropertychange event of the text box with the id of money.
The code below even blocks the decimal point
$("#phone").bind("propertychange", function() {
if(""!=this.value){
var str = this.value.replace(/(^s*) |(s*$)/g, "");
if(this.value != str )
this.value = str;
}
if (this.value.indexOf(' .') != -1) {
this.value = this.value.replace(/[.]/, '');
this.focus(); }
if (isNaN(Number (this.value))) {
this.value = ($.trim(this.value)).replace(/[D]/, '');
this.focus(); } }) ;
Finally, it is best to block the input method. This can be achieved through css, ime-mode:disabled.
If it is very strict, you can add a prohibition on pasting and dragging.
How to prohibit pasting and dragging
Prohibit dragging and pasting in the text box
Implement the function of prohibiting dragging and pasting in the text box in css
Create a Css as follows:
.TextBox_NotDragpaste
{
ondragenter:expression(ondragenter=function(){return false;});
onpaste:expression(onpaste=function(){return false;});
}
If you still need to disable the function of inputting Chinese, you only need to add one more sentence.
is as follows:
.TextBox_NotDragpaste
{
ime-mode:disabled;
ondragenter:expression(ondragenter=function(){return false;});
onpaste:expression(onpaste=function(){return false;} );
}