ASP.NET MVC [RegularExpression] Attribute does not work in all string matches

It seems I can not find a similar topic in Stack regarding this, so here:

Why is this when I point against my MVC MVC view model class the following definition:

[Required]
[RegularExpression(@"\A\d{3,4}\Z",
   ErrorMessage = "The security code (CVN) must be between 3 - 4 digits long.")]
[Display(Name = "Card Security Code (CVN)")]
public string CardCVN { get; set; }

That on my unobtrusive client-side validation, the regular expression cannot be validated? (and then displays the form field error).

It seems as soon as my regex is changed to [RegularExpression(@"\d{3,4}"..., removing all the string matching technique, is it perfect? and it seems like a jquery check that displays, even if it is not applied \Aor \Z, it still matches only the whole string match (doing what I originally needed!); Did I miss something?

Thank.

+5
2

JavaScript, JS \A, \Z \Z. ^ $, . , , . , ASP.NET MVC.

+3

: @"^\d{3,4}$"

^ - .

$ - .

+2

All Articles