Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working an an asp.net core app.

I have validation in place..

I am trying to prohibit the user from entering only spaces. So I use this:

    [Display(Name = "Reason for Cancellation")]
    [Required]
    [RegularExpression(@"w", ErrorMessage = CancellationValidationErrorMessage)]
    [StringLength(245)] // 245 characters to allow for History Type prefix to be added
    public string CancelJustificationComments { get; set; }

And whilst the error pops up stating that i must supply an entry I also get the error on any other input as well.

What is wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
141 views
Welcome To Ask or Share your Answers For Others

1 Answer

The regex validator requires that the whole text matches the regex. So this w only matches a single character entry.

Solution: add some wildcards around it: .*w.*


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...