它看起來像你雙反斜槓你的反斜槓。這是有幫助的使用@
語法字符串聲明,以避免這種混亂:
public const string Email = @"^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$";
你會沒有雙逃逸接近:
public const string Email = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$";
的\[
匹配@
後大概也是一個錯,留下...
public const string Email = @"^([a-zA-Z0-9_\-\.]+)@(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$";
也許你可以提供一個示例「錯誤的條目」,由您的代碼不正確驗證? – richardtallent