给定一个只接受一个输入字符的文本字段,如下所示:
<input type="text" maxlength="1" name="k1" placeholder="?" />
Run Code Online (Sandbox Code Playgroud)
是否有可能进一步限制文本输入,使得只有一个1,X或2(如投注系统)验证?
<input type="text" max-length="1" name="k1" placeholder="?" pattern="[ABC]" />
Run Code Online (Sandbox Code Playgroud)
将允许字母A,B和C.您可以用任何你想要的东西替换A,B和C.
浏览器支持:http://caniuse.com/#feat=input-pattern
正则表达式指南:https://msdn.microsoft.com/en-us/library/az24scfc(v = vs.110).aspx