如何在HTML中新增一個用於檢查輸入元素值的正規表示式?

WBOY
發布: 2023-08-19 19:33:12
轉載
592 人瀏覽過

如何在HTML中新增一個用於檢查輸入元素值的正規表示式?

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的模式屬性指定。以下輸入類型與此屬性相容:文字、密碼、日期、搜尋、電子郵件等。

Syntax

以下是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

對於type="password"

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 ("*").

Example

在下面的範例中,我們使用了元素,其類型為」password」。




   
登入後複製

在執行上述腳本時,它將產生一個類型為密碼的輸入字段,並設定一個模式以確保它滿足限制條件才能提交,否則將顯示一個警示框。

For input field restricted with three letters

在這種情況下,我們限制了輸入字段,只允許使用者輸入三個字母。

Example

Considering the following we are using the input field restricted with three letters with no numbers or special characters.




   


登入後複製

當腳本被執行時,它將顯示一個帶有名稱「countrycode」的輸出,以及一個僅限於三個字母的提交按鈕。如果不符合限制,它將顯示一個警告框。

以上是如何在HTML中新增一個用於檢查輸入元素值的正規表示式?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!