Home > php教程 > php手册 > body text

限制文本框只能输入数字,小数点,英文字母,汉字

WBOY
Release: 2016-06-06 20:01:24
Original
1860 people have browsed it

1.文本框只能输入数字代码(小数点也不能输入): input onkeyup="this.value=this.value.replace(//D/g,'')" onafterpaste="this.value=this.value.replace(//D/g,'')" 2.只能输入数字,能输小数点. (方法1) input onkeyup="if(isNaN(value))execCommand('undo'

 

 

1.文本框只能输入数字代码(小数点也不能输入): 

 

 

2.只能输入数字,能输小数点. (方法1) 

 

 

 

3.数字和小数点方法二 

 

 

4.只能输入字母和汉字 

 

 

5.只能输入英文字母和数字,不能输入中文 

 

 

6.只能输入数字和英文 

 

 

7.小数点后只能有最多两位(数字,中文都可输入),不能输入字母和运算符号: 

 

 

8.小数点后只能有最多两位(数字,字母,中文都可输入),可以输入运算符号: 

 

 

 

 

调用onkeypress事件实现 限制文本框只能输入数字及小数点(并且只能输入1次) 

function KeyPress(objTR) 

   var txtval = objTR.value; 

   var key = event.keyCode; 

   if((key 57)&&key !=46) 

   { 

         event.keyCode = 0; 

   } 

   else 

   { 

         if(key == 46) 

         { 

               if(txtval.indexOf(".") != -1 || txtval.length == 0) 

                     event.keyCode = 0; 

         } 

   } 

 

}

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!