Click here to Skip to main content
10,500,000 members (76,037 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Javascript jQuery
I have a Textbox which contains comma separated values like this tags1,glassware,cermamics

Now I need a solution user only type maximum 16 character before (,) comma. and Total comma separted value not more than 20. I am Unable to handle this.

Please provide me your best solution.

Thanks & Regards
Prince Sharma
Software Developer
Seasia Infotech Pvt. Ltd.
Posted 8-Feb-13 19:18pm
Sergey Alexandrovich Kryukov at 9-Feb-13 1:23am
Why torturing your user that badly?! What did you try?
Sandeep Mewara at 9-Feb-13 14:27pm
Any effort?
VishwaKL at 10-Feb-13 23:57pm
its not a good idea, to stop the user, if the user want enter more value then you have to change the code again, dont restrict the user
BrianHamilton at 21-Feb-13 14:50pm
Would need to see your code but you could use a regular expression, String.split or a variation of substr and indexOf()

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi Guys,

I have done code for that..this is the solution

$('#txtAddTags').keyup(function () {
                var TotalTags = $('#txtAddTags').val().split(',');
                if (TotalTags.length <= 20) {
                    for (var Index = 0; Index < TotalTags.length; Index++) {
                        if (TotalTags[Index].length <= 16) {
                        else {
                            alert('Max chars should be 16.');
                            TotalTags[Index] = TotalTags[Index].substr(0, TotalTags[Index].length - 1);
                            // TotalTags[Index] = TotalTags[Index].substr(16);
                            var TagValue = "";
                            for (var i = 0; i < TotalTags.length; i++) {
                                TagValue += TotalTags[i] + ","
                            TagValue = TagValue.substr(0, TagValue.length - 1);
                            //$('#txtAddTags').val($('#txtAddTags').val().substr(0, $('#txtAddTags').val().length - 1))
                            //$('#txtAddTags').val($('#txtAddTags').val().substr(0, $('#txtAddTags').val().length - 1))
                            return false;
                else {
                    alert('Max tag should be 20.');
                    $('#txtAddTags').val($('#txtAddTags').val().substr(0, $('#txtAddTags').val().length - 1))
                    return false;
Mohibur Rashid at 30-May-13 3:52am
you came to sense

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS

Advertise | Privacy | Mobile
Web04 | 2.8.150723.1 | Last Updated 30 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100