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>
精彩评论