Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:49:52+00:00 2026-05-24T00:49:52+00:00

I would like to validate password length on edit if password is entered otherwise

  • 0

I would like to validate password length on edit if password is entered otherwise empty should be considered ok.

I have seen suggestions to skip the attribute for the password in the edit model and do the validation in the code, but I want to use attributes for all validation.

It seems like there should be something like this already in the library. Have I simply missed it?
I’m using EntLib 5 VAB and MVC 2 on AspNet 3.5.

Vanilla edit model:

[PropertiesMustMatch("Password", "ConfirmPassword", ErrorMessage = "The password and confirmation password do not match.")]
public class EditAccountModel
{
    public Guid ProviderUserKey { get; set; }

    [Required]
    [DisplayName("User name")]
    public string UserName { get; set; }

    [Required]
    [Email(ErrorMessage = "Not a valid email")]
    [DataType(DataType.EmailAddress)]
    [DisplayName("Email address")]
    public string Email { get; set; }

    //[ValidatePasswordLength] <- Requires password
    [DataType(DataType.Password)]
    [DisplayName("Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [DisplayName("Confirm password")]
    public string ConfirmPassword { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:49:52+00:00Added an answer on May 24, 2026 at 12:49 am

    ValidatePasswordLengthAttribute is not part of the MVC core, but is created within your project from the default MVC project template, in AccountModels.cs. You can freely modify its implementation. Change the IsValid method to accept null and the empty string as valid values.

    public override bool IsValid(object value) {
        string valueAsString = value as string;
        return String.IsNullOrEmpty(valueAsString) || valueAsString.Length >= _minCharacters);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some MET data I want to validate which would look something like
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to know how one could validate a password with regex. I
I have a session['password']. I would like to get the session value and use
I have a dashboard with users details which they can edit. I would like
I have several variables and I would like to validate them before writing them
I would like to validate an email using the RegexValidator, e.g. [RegexValidator(@^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$)] Which works
I'm using jQuery Validate and would like to re-validate a group of fields whenever
Would like to know what a programmer should know to become a good at
I'm using jQueryValidation and I would like to validate my form without needing to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.