The pattern attribute of the <input> tag

Definition and Usage

The pattern attribute specifies the pattern used to validate the input field.

A pattern refers to a regular expression.

Note: The pattern attribute applies to the following types: text, search, url, telephone, email, and password.

Tip: Please use the standard "title" attribute to describe the schema.

grammar

<input pattern="regexp">
值	regexp
描述 规定用于输入字段的模式。

<!DOCTYPE HTML>
<html>
<body>
// 只能包含三个字母的文本字段(数字或特殊字符):
<form action="/example/html5/demo_form.asp" method="get">
国家代码:<input type="text" name="country_code" pattern="[A-z]{3}"
title="三个字母的国家代码" />
<input type="submit" />
</form>

</body>
</html>
	

Guess you like

Origin blog.csdn.net/Depressiom/article/details/123681906