我想通過使用帶有模式屬性的 html 5 來驗證巴基斯坦格式的電話號碼。有效的巴基斯坦電話號碼格式是:+92 345 1234567但是當我在輸入字段中輸入此內容時,它會顯示以下錯誤:請匹配請求的格式 <!DOCTYPE html><html><head> <title> Web Course </title></head><body> <form> Enter your phone number: <input type="text" pattern="[+][0-9]{2}[][0-9]{3}[][0-9]{7}" /> <input type="submit" value="submit" /> </form></body></html>
1 回答

慕虎7371278
TA貢獻1802條經驗 獲得超4個贊
您可以使用以下解決方案之一:
<form>
Enter your phone number (with spaces):
<input type="tel" pattern="[+][0-9]{2} [0-9]{3} [0-9]{7}">
<input type="submit" value="submit">
</form>
<form>
Enter your phone number (without spaces):
<input type="tel" pattern="[+][0-9]{12}">
<input type="submit" value="submit">
</form>
<form>
Enter your phone number (with or without spaces):
<input type="tel" pattern="[+][0-9]{2} ?[0-9]{3} ?[0-9]{7}">
<input type="submit" value="submit">
</form>
- 1 回答
- 0 關注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消