yeungmankit 于 2014.11.11 11:26 提问
- MVC4 RegularExpression验证出现问题
-
using System;
using System.ComponentModel.DataAnnotations;namespace Webdiyer.MvcPagerDemo.Models
{
public class Users
{
public int ID { get; set; }[DataType(DataType.PhoneNumber)] public int MinPrice { get; set; } [RegularExpression(@"^(0|[1-9][0-9]*)$", ErrorMessage = "MaxPrice的格式不正确")] public int? MaxPrice { get; set; } }
}
MinPrice 验证是正常的,输入英文字母等会报"The field MinPrice must be a number." MaxPrice 输入0开头的数字会报错,输入abcd和符号类却不会报错,这个正则表达式“^(0|[1-9][0-9]*)$”在别的网站试过了,输入非数字是会报NOT MATCH的,只有输入非0开头的正整数或0才会match。想请教下哪里出现问题了。
View 里面是这样写的
@Html.EditorFor(model => model.MaxPrice)
@Html.ValidationMessageFor(model => model.MaxPrice)
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!