The previously written method has a defect. You can enter a space. Now, spaces are blocked. The space filtering function is added to the previous code. The Code is as follows:
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 to bind to the onpropertychange event of the text box with the id of money.
The following code blocks the decimal point.
The Code is as follows:
$ ("# 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. With css, ime-mode: disabled can be implemented.
If it is very strict, you can add prohibited Pasting and dragging.
How to disable Pasting and dragging
Do not drag or paste the text box
In css, the text box is not dragged or pasted.
Create a Css as follows:
The Code is as follows:
. TextBox_NotDragpaste
{
Ondragenter: expression (ondragenter = function () {return false ;});
Onpaste: expression (onpaste = function () {return false ;});
}
If you want to disable Chinese input, you only need to add one more statement.
As follows:
The Code is as follows:
. TextBox_NotDragpaste
{
Ime-mode: disabled;
Ondragenter: expression (ondragenter = function () {return false ;});
Onpaste: expression (onpaste = function () {return false ;});
}