普通的前pression错误信息 [英] Regular expression error message

查看:111
本文介绍了普通的前pression错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 RegularEx pression(@^ \\ D {1,15} $)] ,我希望用户在输入数字高达15长度,它返回错误信息的'请输入最多15位联系人号码的,如果这是不正确的。

Using the RegularExpression(@"^\d{1,15}$")], I want the user to enter digits up to 15 in length, which returns the error message 'Please enter up to 15 digits for a contact number' if this is not correct

[Required(ErrorMessage = ("Please enter up to 15 digits for a contact number")), Display(Name = "Contact Number"), RegularExpression(@"^\d{1,15}$")]
public string ContactNumber { get; set; }

如果用户未能做到这一点我留下错误信息:

If the user fails to do this I am left with the error message:

The field Contact Number must match the regular expression '^\d{1,15}$'.

而不是'请输入最多15位联系人号码 ...没有人知道为什么吗?
谢谢

instead of 'Please enter up to 15 digits for a contact number'...does anyone know why? thanks

推荐答案

您已经指定了的ErrorMessage RequiredAttribute标签(你完全不需要在这种情况下,因为正规的前pression的)。所以:

You have assigned the ErrorMessage to the RequiredAttribute (which you absolutely don't need in this case because of the regular expression). So:

[Display(Name = "Contact Number")]
[RegularExpression(@"^\d{1,15}$", ErrorMessage = "Please enter up to 15 digits for a contact number")]
public string ContactNumber { get; set; }

这篇关于普通的前pression错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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