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

88
Views
jQuery Validation for 5 maximum values in input field following comma seperator

I am using autocomplete dropdown by following this below link,

https://www.jqueryscript.net/form/tags-autocomplete-dropdown.html

Following is my HTML and jQuery Code,

<div class="pf-field">
     <input type="text" name="categories" id="categories" name="categories" class="tags_input">
</div>

<script>
    $(function(){
    var data = [
        'History',
        'Civics',
        'Geogpraphy',
        'Science',
        'Economics',
        'Arts',
        'Chemistry',
        'Mathematics',
        'Language',
        'Computer',
    ];

    $(".tags_input").tagComplete({

                keylimit: 1,
                hide: false,
                autocomplete: {
                    data: data
                }
        });
});
</script>

Everything is working properly till here. Users can add as many values as they wants. However, I want to limit this by allowing user not to add more than or less than 5 values.

$(function(){
    var $profile = $('#profile');
    if($profile.length){
        $profile.validate({
            errorElement: 'span',
            rules:{
                categories:{
                    required: true
                }

            },
            messages:{
                categories:{
                    required:'Categories are mandatory!'
                }
            }
        })
    }
})

also, This same jQuery Validation is working fine with other input fields but not on working with this autocomplete dropdown.

Can you help me out please, I am find solution about this since last week.

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!