HTML5验证输入框

<input name="" id="" type="text" maxlength="11"  placeholder="用户名" required='required' autofocus="" oninput="setCustomValidity('');" oninvalid="setCustomValidity('用户名不能为空')" />

HTML5知识:

定义默认值:placeholder="用户名"  

验证不为空: required='required'   oninput="setCustomValidity('');" oninvalid="setCustomValidity('用户名不能为空')"       一定要加这个:required='required'

focus输入框:autofocus="autofocus"

验证输入字段为字母: pattern="[a-zA-Z]+"    eg:<input type="text" pattern="[a-zA-Z]+" oninvalid="setCustomValidity('Custom Message')" />

posted @ 2015-01-22 13:24  yanyanmammy  阅读(1053)  评论(0编辑  收藏  举报