Click here to Skip to main content
15,910,121 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
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
Comments
Sergey Alexandrovich Kryukov 9-Feb-13 1:23am    
Why torturing your user that badly?! What did you try?
—SA
Sandeep Mewara 9-Feb-13 14:27pm    
Any effort?
VishwaKL 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 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

Hi Guys,

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

C#
$('#txtAddTags').keyup(function () {
                //debugger;
                //alert('1')
                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(TagValue);
                            //$('#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;
                }
            });
 
Share this answer
 
Comments
Mohibur Rashid 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900