The task we are going to perform in this article is about how to add a regular expression that an input elements value is checked against in HTML.
將用於檢查輸入元素值的正規表示式由HTML的模式屬性指定。以下輸入類型與此屬性相容:文字、密碼、日期、搜尋、電子郵件等。
以下是HTML 標籤的pattern屬性的語法。
For getting more idea on how to add a regular expression that an input elements value is checked against in HTML, let’s look into the following examples
The type="password" attribute on the tag creates a text field where users can safely enter a password. Depending on the browser, characters are replaced as they are entered by a dotor ("•") asterisk ("*").
在下面的範例中,我們使用了元素,其類型為」password」。
在執行上述腳本時,它將產生一個類型為密碼的輸入字段,並設定一個模式以確保它滿足限制條件才能提交,否則將顯示一個警示框。
在這種情況下,我們限制了輸入字段,只允許使用者輸入三個字母。
Considering the following we are using the input field restricted with three letters with no numbers or special characters.
當腳本被執行時,它將顯示一個帶有名稱「countrycode」的輸出,以及一個僅限於三個字母的提交按鈕。如果不符合限制,它將顯示一個警告框。
以上是如何在HTML中新增一個用於檢查輸入元素值的正規表示式?的詳細內容。更多資訊請關注PHP中文網其他相關文章!