输入电子邮件正确格式
I've already covered some subtle HTML5 improvements like placeholder, prefetching, and web storage. Today I want to introduce a few new INPUT element types: email and url. Let's take a very basic look at these new INPUT types and discuss their advantages.
我已经介绍了HTML5的一些细微改进,例如占位符 , 预取和Web存储 。 今天,我想介绍一些新的INPUT元素类型:电子邮件和url。 让我们非常基本地了解这些新的INPUT类型并讨论它们的优点。
语法 (The Syntax)
The syntax is as basic as a text input; instead, you set the type to "email" or "url":
语法和文本输入一样基本。 而是将类型设置为“电子邮件”或“ URL”:
<!-- email -->
<input type="email" pattern="[^ @]*@[^ @]*" value="">
<!-- url -->
<input type="url" value="">
Using the new HTML5 pattern attribute, you can also provide a regular expression to validate the email and URL addresses against. I'll save those specifics for another post.
使用新HTML5模式属性,您还可以提供正则表达式来验证电子邮件和URL地址。 我将这些细节保存在另一篇文章中。
使用type =“ email”和type =“ url”的优点 (The Advantages to Using type="email" and type="url")
There are a few advantages to using these special INPUT types:
使用这些特殊的INPUT类型有一些优点:
- You may easily style all email INPUT elements with input[type=email] 您可以使用input [type = email]轻松设置所有电子邮件INPUT元素的样式。
- You may easily style all url INPUT elements with input[type=url] 您可以使用input [type = url]轻松设置所有url INPUT元素的样式
- This INPUT type could be considered more semantically correct. 可以认为此INPUT类型在语义上更正确。
Mobile accessibility: if your user is browsing with an iPhone and they arrive at a special email input, the iPhone will display a keyboard with the @ symbol provided on the primary screen. If the INPUT is of type "url", the iPhone will display the ".com" button on the primary keyboard screen:
移动辅助功能:如果您的用户正在使用iPhone浏览,并且收到特殊的电子邮件输入,则iPhone将在主屏幕上显示带有@符号的键盘。 如果输入的类型为“ url”,则iPhone将在主键盘屏幕上显示“ .com”按钮:
在此...输入...类型上输入 (Input on this...Input...Type)
At first I disliked the idea of using different type attribute values per field but after more thought, the accessibility and usability enhancements provided a great boost. What do you think?
最初,我不喜欢每个字段使用不同类型属性值的想法,但经过更多思考,可访问性和可用性增强功能带来了极大的推动。 你怎么看?
输入电子邮件正确格式