我需要檢查該字段是否包含重複字符(超過三個)。我在RegularExpressionAttribute中使用正則表達式,但它不起作用。 例如,MVC RegularExpressionAttribute。測試重複字符regexp不起作用
- 圖案:([A-ZA-Z])\ 1 {2}
- 輸入:abcdddf
- 結果:沒有匹配!
具有下面的代碼:
public override bool IsValid(object value)
{
this.SetupRegex();
string str = Convert.ToString(value, CultureInfo.CurrentCulture);
if (string.IsNullOrEmpty(str))
{
return true;
}
Match match = this.Regex.Match(str);
return ((match.Success && (match.Index == 0)) && (match.Length == str.Length));
}
相反,如果串
return ((match.Success && (match.Index == 0)) && (match.Length == str.Length));
只有
return match.Success;
那麼這個問題將得到解決。 是否有任何想法如何解決這個限制,而不需要實現一個自定義的RegularExpressionAttribute?可能本身就是對其他人的正規表達?
已更新此產品,可能會收取額外費用! – user1199305 2012-02-09 12:17:45