开发者

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

开发者 https://www.devze.com 2023-04-04 21:26 出处:网络
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.

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

精彩评论

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