开发者

How to make the textField first character to start with alphabet only?

How to make the textField first character to be alphabet only开发者_JS百科?


Use regular expressions to check it contents in keydown event. If it start from non letter character then clear the textbox. You can use regular expressions to check what's the first character.

For example:

<input type="text" onkeydown="javascript:checkContents(this)" />

<script type="text/javascript">
   var checkContents = function(input) {
      var text = input.value;
      if(!/[a-zA-Z]/.test(text))
         input.value = ""; 
   }
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜