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

112
Views
Making a jQuery Custom Validator Optional

I added a custom validation method to jQuery Validation such as:

$.validator.addMethod('myregex', function (value) {
    return /\d/.test(value);
}, 'Please enter a valid input.');

Note that I know there is a build in number check. That is just an example, I actually want to use more custom regex validators.

The problem is that now the field form is always required. Even if I set the value required to false in the code such as:

   $("form[name='my-form']").validate({
        // Specify validation rules
        rules: {
            form-field: {
                required: false,
                myregex: true
            },

I want my regex to check if the data entered on a field is valid, but not force the field to be completed as its optional.

about 4 years ago · Juan Pablo Isaza
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!