gpt4 book ai didi

c# - 自定义属性的 Jquery 客户端验证

转载 作者:行者123 更新时间:2023-12-01 02:48:22 24 4
gpt4 key购买 nike

我创建了一个自定义验证属性:

public sealed class DateAttribute : DataTypeAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="EmailAddressAttribute"/> class.
/// </summary>
public DateAttribute() : base(DataType.Date)
{
}

/// <summary>
/// Checks that the value of the data field is valid.
/// </summary>
/// <param name="value">The data field value to validate.</param>
/// <returns>
/// true always.
/// </returns>
public override bool IsValid(object value)
{
DateTime inputDate = Convert.ToDateTime(value, CultureInfo.CurrentCulture);

if (inputDate.Date >= DateTime.Now.Date.AddMonths(-2) && inputDate.Date <= DateTime.Now.Date.AddMonths(2))
return true;

return false;
}
}

上面的代码需要回传到服务器,我怎样才能让它在客户端使用jquery工作?

谢谢,-纳伦

最佳答案

Stuart Leeks 有一篇关于使用 jquery datepicker 构建日期范围验证器(包括客户端)的博客文章。

它可能超出您的需要,但它绝对会满足您的需求。

ASP.NET MVC 3: Integrating with the jQuery UI date picker and adding a jQuery validate date range validator

关于c# - 自定义属性的 Jquery 客户端验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6263761/

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