1. 程式人生 > >input 輸入框 只能輸入數字、字母、漢字等

input 輸入框 只能輸入數字、字母、漢字等

from:https://www.cnblogs.com/phpfensi/p/7298617.html

1.文字框只能輸入數字程式碼(小數點也不能輸入)

<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
<br><br>
2.只能輸入數字,能輸小數點.
<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
<input name="txt1" onchange="if(/\D/.test(this.value)){alert('只能輸入數字');this.value='';}">
<br><br>
3.數字和小數點方法二
<input type="text" t_value="" o_value="" onkeypress="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value" onkeyup="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value" onblur="if(!this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))this.value=this.o_value;else{if(this.value.match(/^\.\d+$/))this.value=0+this.value;if(this.value.match(/^\.$/))this.value=0;this.o_value=this.value}">
<br><br>
4.只能輸入字母和漢字
<input onkeyup="value=value.replace(/[\d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))" maxlength="10" name="Numbers">
<br><br>
5.只能輸入英文字母和數字,不能輸入中文
<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
<br><br>
6.只能輸入數字和英文<font color="Red">chun</font>
<input onkeyup="value=value.replace(/[^\d|chun]/g,'')">
<br><br>
7.小數點後只能有最多兩位(數字,中文都可輸入),不能輸入字母和運算子號:
<input onkeypress="if((event.keyCode<48 || event.keyCode>57) &amp;&amp; event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false">
<br><br>
8.小數點後只能有最多兩位(數字,字母,中文都可輸入),可以輸入運算子號:
<input onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')">
<br><br>
輸入中文:
<input type="text" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">  
<br><br>
輸入數字:  
<input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')">  
<br><br>  
輸入英文:  
<input type="text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">  
 <br><br>
三個合在一起  
<input onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')">  
 <br><br>
只輸入數字和字母  
:<input class="input" maxlength="12" size="15" name="username" id="username" onkeyup="value=value.replace(/[\W]/g,'')">
<br><br>
除了英文的標點符號以為 其他的人都可以中文,英文字母,數字,中文標點
<input type="text" onkeyup="this.value=this.value.replace(/^[^
[email protected]
#$%^&amp;*()-=+]/g,'')">

相關推薦

input 輸入 只能輸入數字字母漢字

from:https://www.cnblogs.com/phpfensi/p/7298617.html 1.文字框只能輸入數字程式碼(小數點也不能輸入) <input onkeyup="this.value=this.value.replace(/\D/g,'')"

表單驗證input 輸入 只能輸入數字字母漢字

1.文字框只能輸入數字程式碼(小數點也不能輸入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')

input輸入只能輸入正整數字母小數漢字

只需將需要的程式碼加入到input輸入框中,即可使用! 1,文字框只能輸入數字程式碼(小數點也不能輸入) 程式碼如下: <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value

購物車中的input輸入只能輸入數字輸入為0的時候默認為1

pos put brush pre tex || lac ext html <input type="text" value="1" onkeyup="value=(parseInt((value=value.replace(/\D/g,‘‘))==‘‘||pars

在HTML中限制input 輸入只能輸入數字

限制 input 輸入框只能輸入純數字 1. onkeyup = "value=value.replace(/[^\d]/g,'')" 使用 onkeyup 事件,有 bug ,那就是在中文輸入法狀態下,輸入漢字之後直接回車,會直接輸入字母   2.

input 輸入只能輸入數字,長度為2(也可以修改任意長度)

直接放在input標籤裡面 1.input長度為2 oninput="if(value.length>2)value=value.slice(0,2)"  2.控制input輸入數字 on

js實現input輸入只能輸入數字的功能(完美測試通過)

<input type="text" style="ime-mode:disabled;" onpaste="return false;" onkeypress="keyPress()" /> function keyPress() { var k

input 輸入只能輸入數字

1、onkeyup = "value=value.replace(/[^\d]/g,'')" 使用 onkeyup 事件,有 bug ,那就是在中文輸入法狀態下,輸入漢字之後直接回車,會直接輸入字母   2、onchange = "value=value

input 輸入只能輸入數字,長度為2(也可以修改任意長度);input只能輸入數字或小數

直接放在input標籤裡面 1.input長度為2 oninput="if(value.length>2)value=value.slice(0,2)"  2.控制input輸入數字 onkeyup="if(this.value.length==1){this.v

JS通過正則限制 input 輸入只能輸入整數小數(金額或者現金) 兩位小數

第一: 限制只能是整數 ? 1 <input type = "text" name= "number" id = 'number' onkeyup= "if(! /^d+$/.t

前端頁面中input輸入只能輸入數字

input輸入框只能輸入數字 在實際的專案中,有很多輸入框,比如說年齡欄位,身高欄位等等,要求使用者輸入的是純數字,為了簡單,我們可以直接在input標籤中新增onkeyup對輸入的內容進行驗證,如下程式碼: <input type="text" placehold

js jquery 限制input輸入只能輸入兩位小數的數字

//正整數 兩位小數 $('.inputWrap').on('input', function () { var num = $(this).val(); if(n

input輸入只能輸入正整數輸入正整數和小數

input 輸入數字類的一些判別  方法一:實現輸入框只能輸入正整數,輸入同時禁止了以0開始的數字輸入,防止被轉化為其他進位制的數值。 <input type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,

js控制輸入只能輸入數字不能輸入其他字元

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"

限制輸入只能輸入數字

<th class="form_label" width="15%" align="right"  style="border-bottom: 1px;" >                

onkeyup限制輸入只能輸入數字

例子:html程式碼 <input type="text" name="" id="box" /> 通常都直接用: <input type="text" name="" id="box" onkeyup="value=value.replace(/[^\

input輸入只能輸入正整數

input輸入框加入限制只能輸入正整數,輸入其他字元會自動清除: html的寫法: <input type="text" id="price" onkeyup="if(this.val

使用正則表示式限制輸入只能輸入數字

正則表示式限制輸入框只能輸入數字      程式碼如下: <input type="text" onkeyup="this.value=this.value.replace(/[^/d]/g,'') " onafterpaste="this.value=this.v

js驗證只能輸入漢字 只能輸入數字 只能輸入英文和數字 控制輸入只能輸入

只能輸入漢字: <input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData

JS驗證輸入只能輸入數字,並且只能含有2位小數

<script language="JavaScript" type="text/javascript"> //輸入框只能輸入數字,並且只能含有2為小數 function clearNoNum(obj){ obj.value = obj.value.replace(/[^\d.]/g,""); /