Codeone
Codeone

Reputation: 1201

How to validate Uppercase in MVC

I'm developing a MVC project, I want to validate it for some text filed are uppercase. How can I do it? I'm using this **text-transform:uppercase** but I want to validate in model

[DisplayName("Last Name :")]
            [Required]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Last Name must be between 3 and 50 characters!")]
            public string LastName { get; set; }

Upvotes: 2

Views: 3234

Answers (1)

Akshey Bhat
Akshey Bhat

Reputation: 8545

[RegularExpression(@"[A-Z]{3,50}$", 
         ErrorMessage = "Only uppercase Characters are allowed.")]

use regular expression attribute.

Upvotes: 4

Related Questions