輸入框輸入只能輸入字母

方式一java

$('#surname_id,#firstname_id').bind("keyup change",function() {
	this.value=this.value.replace(/[^a-zA-Z]/g,'');//把非字符的替換爲空
});
	 
 $('#certNo_id').bind("keyup change",function() {			
	this.value=this.value.replace(/[^a-zA-Z0-9]/g,''); 
	this.value=this.value.substr(0,18);	       
});
		
<input class="inputTipsRight width8Em" type="text" id="surname_id" name="surname" placeholder="請輸入英文或拼音" />

方式二this

$("#aolastName").on('keyup change input',function(e){
var keyword=this.value.toLowerCase();//獲取文本框的值
      if(keyword.match(/[^\a-\z\A-\Z]/g)!=null){//若是匹配到了,爲空
	   this.value = "";
   }
});
相關文章
相關標籤/搜索