数据注释MVC3 [英] Data Annotation MVC3

查看:130
本文介绍了数据注释MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用的DataAnnotations来限制用户从输入特殊字符?

Is it possible to use DataAnnotations to restrict user from enter special character?

我希望用户只输入包括AZ,az和0-9成一个文本框。

I want the user to enter only A-Z, a-z and 0-9 into a textbox.

我需要做这个客户端上。

I need to do this on the client side.

推荐答案

是的,你可以使用普通的防爆pression为...

yes you can use Regular Expression for that...

[Required(ErrorMessage = "Enter Foo !")]
[RegularExpression(@"^[a-zA-Z0-9]+$", ErrorMessage = "Incorrect Entry dude !")]
public string Foo { get; set; }

这篇关于数据注释MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆