Durgpal Singh
Durgpal Singh

Reputation: 11953

Regular expression is not working in mvc

I am using regular expression in my mvc project but its not working. It is always showing error. can anyone tell me is it correct or not if yes then why is not working. Thats is my Model.

public partial class State
    {
        public int StateId { get; set; }
        [Required]
        [RegularExpression(@"^(([A-za-z]+[\s]{1}[A-za-z]+))$", ErrorMessage = "State Name must be alphabetic")]
        public string StateName { get; set; }
        [Required]
        [Range(1, 10)]
        public Nullable<int> CountryId { get; set; }
        [Required]
        public Nullable<System.DateTime> startdate { get; set; }
    }

Upvotes: 0

Views: 2437

Answers (1)

Anuja
Anuja

Reputation: 654

This would be the expression ^[A-za-z]+(([\s]{1})?[A-za-z])+$

You can use http://rubular.com/ to validate regular expression.

Upvotes: 1

Related Questions