Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

555
Views
jQuery Validation - password MUST contain uppercase and number

So in my registration form I have this field:

 <div class="form-group">
    <label for="RegisterModel_Password">Password</label>
    <input type="password" id="RegisterModel_Password" 
           name="RegisterModel.Password" class="form-control" 
           required="required" minlength="8"/>
</div>

As you see, I'm using jQuery validation attributes to ensure that the password includes at least 8 characters. So, I want to check if password contains uppercase and number, if not, field is not valid. I downloaded additional method for jQuery Validation plugin named "pattern" and added her in head tag.

I tried to do this as follows but it didn't worked.

$("#formRegister").validate({
    rules: {
        RegisterModel_Password: {
            pattern: /^[a-zA-Z][0-9]/
        }
    }
});

I assume that the pattern is wrong, but I'm not sure whether the use is correct. Thank you for your help.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Chains of regular expressions are too hard for me ( I have never tried to learn them lol ). So here is my solution:

jQuery.validator.addMethod("passwordCheck",
        function(value, element, param) {
            if (this.optional(element)) {
                return true;
            } else if (!/[A-Z]/.test(value)) {
                return false;
            } else if (!/[a-z]/.test(value)) {
                return false;
            } else if (!/[0-9]/.test(value)) {
                return false;
            }

            return true;
        },
        "error msg here");

And simply I use it like a attribute:

<input type="password" id="RegisterModel_Password" 
name="RegisterModel.Password" 
class="form-control" 
required="required" minlength="8" 
passwordCheck="passwordCheck"/>

Thanks for your answers.

about 4 years ago · Santiago Trujillo Report

0

You can add your custom validation using $.validator.addMethod() like:

$.validator.addMethod("validation_name", function(value) {
    // at least 1 number and at least 1 character
    [^\w\d]*(([0-9]+.*[A-Za-z]+.*)|[A-Za-z]+.*([0-9]+.*))
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!