mvc3怎么使用JS验证邮箱 正则表达式的@要出错,怎么解决????

JavaScript014

mvc3怎么使用JS验证邮箱 正则表达式的@要出错,怎么解决????,第1张

mvc3验证当然首选模型验证了。

[DataType(System.ComponentModel.DataAnnotations.DataType.EmailAddress)]

public string UserEmail { getset}

只要你声明 DataType(System.ComponentModel.DataAnnotations.DataType.EmailAddress)就会自动帮你验证字段是不是正确的邮箱

输出字符串@:"www"

regexValidator({ regexp: @:"^[\\w|\\u4e00-\\u9fa5|\@|\\.|\\-]{2,40}$", onerror: "用户名格式错误" })

...用JS验证或者用验证控件啊。

不过一般客户端验证了 服务3、端还会验证 。 因为有的浏览器不支持Javascript

客户端验证:

<script language="javascript" type="text/javascript">

function fn()

{

var str = document.getElementById("TextBox1").value

if(str.length==0)

{

alert("输入不能为空")

document.getElementById("TextBox1").focus()

return false

}

}

</script>