gpt4 book ai didi

.net - 数据注解 MVC3

转载 作者:行者123 更新时间:2023-12-01 14:37:31 25 4
gpt4 key购买 nike

是否可以使用DataAnnotations来限制用户输入特殊字符?

我希望用户只在文本框中输入 A-Z、a-z 和 0-9。

我需要在客户端执行此操作。

最佳答案

您可以尝试使用 [RegularExpression]属性:

[RegularExpression(@"^[a-zA-Z0-9]+$")]
public string Foo { get; set; }

它也支持不显眼的客户端验证,因此这个正则表达式将在客户端进行转换。

关于.net - 数据注解 MVC3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11554893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com