2012-08-30 59 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"); 

} 

});