Skip to content
Loading
  • +1
    Hi Farhan
     
      It is still accepting more than 4 characters & not giving any message
     
    Thanks 
    +1
  • Sachin Singh
    +1
    after the below code
    1. Required(ErrorMessage = "Id can not be blank.")]    
    2. [MaxLength(4, ErrorMessage = "Max length should be less than or equal to 4.")]     
    3. [RegularExpression("([0-9]+)", ErrorMessage = "Please enter valid Number")]     
    4. public int Id { get; set; }    
    you just need to include the client side scripts in your view.
    1. Jquery.Validate  
    2. Jquery.validate.Unobtrusive. 
    3.    
    1. @Html.ValidationMessageFor(x=>x.Id)   
    +1
  • +1
    Hi Sachin
     
       Only in case of length it is giving problem. Do i need to include script files again
     
    Secondly is there any way so that i don't require to include Script files in every view.
     
    Thanks 
    +1
  • Sachin Singh
    +1
    I just saw that your Id is an integer, then instead of max length use the range attribute.
     
    1. [Range(1,9999,ErrorMessage="you can only enter upto 4 digits")]  
    +1
  • +1
    Hi Sachin
     
      ID is a string 
     
    Thanks 
    +1