2013-05-10 103 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