2013-05-10 23 views
3

有谁知道我可以在具有MVC页面的HTML5电子邮件输入的模式属性中使用“@”吗?在HTML5输入模式属性中使用“@”与MVC

<input type="email" pattern="^[a-zA-Z0-9._+-][email protected][a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"> 

在运行时,我得到这个错误:

"[" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.

当我使用的,而不是“模式”我可以用“@@”转义“数据模式”,而是用“模式”是也失败了。

感谢提前:)

回答

12

这是可以做到2种方式:

通过剃刀渲染 “@”:

<input type="email" pattern="^[a-zA-Z0-9._+-][email protected]("@")[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"> 

随着HTML编码:

<input type="email" pattern="^[a-zA-Z0-9._+-]+&#64;[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"> 
+1

伟大的东西,不知道为什么这没有更多upvotes! – 2013-12-16 11:04:04