且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

验证仍然不能解决普通EX pression,只允许数字

更新时间:2023-12-04 15:11:34

我想通了。它原来是一个非常模糊的监督。对于普通的前pression的DataAnnotation应该有引号前的@。

I figured it out. It turned out to be a very obscure oversight. The DataAnnotation for the Regular expression should have the @ before the quotation marks.

代替这样的:
[RegularEx pression(@(^ [0-9] + $)的ErrorMessage =无效的。只能使用数字。)]

Instead of this: [RegularExpression("@(^[0-9]+$)", ErrorMessage = "Invalid. Must use only numbers.")]

我需要有这样的:
[RegularEx pression(@(^ [0-9] + $)的ErrorMessage =无效的。只能使用数字。)]

I need to have this: [RegularExpression(@"(^[0-9]+$)", ErrorMessage = "Invalid. Must use only numbers.")]

我真的需要获得更大的咖啡杯:)

I really need to get a bigger coffee mug :)