简体   繁体   中英

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

如何使textField第一个字符只是字母?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM