我有一个用户必须在其中输入他的电话号码的表单。
<input id="username" title="Please enter valid phone number " maxlength="10" pattern="[0-9]{10}" name="phone" size="20"
required oninvalid="setCustomValidity('Please enter a valid phone number.')" onchange="try{setCustomValidity('')}catch(e){}" >
验证时效果很好,但仅限于数字。 我希望号码特别从 971 开始,因为它仅限于阿联酋号码。我怎样才能做到这一点
最佳答案
首先尝试添加该数字并减少出现次数
pattern="971[0-9]{7}"
<input id="username" title="Please enter valid phone number " maxlength="10" pattern="971[0-9]{7}" name="phone" size="20"
required oninvalid="setCustomValidity('Please enter a valid phone number.')" onchange="try{setCustomValidity('')}catch(e){}" >
关于regex - 电话号码的自定义 html5 验证正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36718139/