2012-08-30 58 views
0

在HTML中,我需要限制進入文本框的用戶應當與一個特定的字符/數字開始啓動,限制文本框與特定字符

(例如:數量6-在這種情況下,用戶可以輸入在文本框中輸入數字,僅與「6」)

感謝

+0

你有什麼試過的?在社區提供幫助之前,鼓勵您首先嚐試自己解決問題。 –

回答

2

類似下面的開始?

<input onblur="if (!/^6/.test(this.value)) alert('Ooops');"> 
+0

感謝它的工作! – swathi

1

你想用一塊javascript來檢查這個客戶端。不要忘記也要驗證輸入服務器端!每個人都沒有啓用JavaScript,惡意用戶可以禁用它來規避檢查。

0
$("#textbox").on("keypress",function(e){ 

//you can use e.which or e.keyCode based on the browser 
//check if it is the first character 
//here i used 56 as it is keycode for your example of 6 
if($("#textbox").val().length ==0 && e.which == 56) 
{ 

    alert("yes i accept"); 

} 
else 
{ 

    alert("no i dont accept"); 

} 

});