」。"/> 」。">

首頁  >  文章  >  web前端  >  html5碼中pattern的意思是什麼

html5碼中pattern的意思是什麼

WBOY
WBOY原創
2022-09-13 16:48:273432瀏覽

在html5中,pattern是驗證輸入欄位的意思;pattern屬性規定用於驗證輸入內容的正規表示式,要求使用者必須依照正規表示式的規則輸入訊息,防止輸入錯誤;text、search 、url等多種類型的文字輸入框都支援此屬性,語法為「」。

html5碼中pattern的意思是什麼

本教學操作環境:windows10系統、HTML5版本、Dell G3電腦。

html5程式碼中pattern的意義是什麼

pattern屬性規定用於驗證輸入內容的正規表示式,要求使用者必須按正規表示式的規則輸入訊息,防止輸入錯誤。 text、search、url、telephone、email、password等類型的文字輸入框都支援pattern屬性。如,這個文字方塊要求使用者必須輸入數字。

pattern 屬性規定用於驗證輸入欄位的模式。

模式指的是正規表示式。

範例如下:

<!DOCTYPE HTML>
<html>
<body>
<form action="/example/html5/demo_form.asp" method="get">
<input name="country_code" type="text" pattern="[0-9]" title="0-9" />
<input type="submit" />
</form>
</body>
</html>

 提交表單時,如果使用者輸入的資訊不符合正規表示式的要求,本例中輸入非數字,則瀏覽器會阻止提交表單,並顯示警告訊息。

html5碼中pattern的意思是什麼

(學習影片分享:css影片教學html影片教學

#

以上是html5碼中pattern的意思是什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn