Lam*_*fif 3 html regex html5 razor asp.net-mvc-4
我有一个razor应用程序,我想在视图中添加电子邮件验证
<td><input type="text" name="mail" placeholder="me@example.com" required autofocus title="" pattern="/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/"/> </td>
Run Code Online (Sandbox Code Playgroud)
但在这里我得到了这个句法错误
"[" Is not valid at the start of a block of code. Only identifiers, keywords, comments, "(" and "{" are valid.
有什么问题?我该如何解决?
尝试用@@逃避@.
如果没有,请将其放在"{"或"("并检查.
它可以通过两种方式完成:
通过剃刀渲染"@":
<input type="email" pattern="^[a-zA-Z0-9._+-]+@("@")[a-zA-Z0-9.-]+\.[a-zA-Z]{2,9}$">
Run Code Online (Sandbox Code Playgroud)
使用HTML编码:
<input type="email" pattern="^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,9}$">
Run Code Online (Sandbox Code Playgroud)