0

I have a requirement where the user can enter/copy-paste 25 ids separated by comma in a textarea ; there is no maximum size for the ids.Thereafter he cannot enter any characters.He then submits those ids for search.

Is there any way to limit the id number to 25 and then not allowing the user to enter anything. I cannot use maxlength here.Also all these checking have to happen before user submits and the control reaches the angularjs controller. I am using angularjs,HTML5,CSS3,bootstrap.

Bidisha
  • 287
  • 1
  • 5
  • 16

2 Answers2

0

You can split the model of the input on ng-change like this for example ( where textareaValue is the model of the textarea ):

var textareaValueArray = textareaValue.split(',');

    if( textareaValueArray.length > 25 ) 
        textareaValue =  textareaValueArray.slice(0,25).join(',')
guramidev
  • 2,228
  • 1
  • 15
  • 19
0

Basically what you'd need to is count the number of commas in the string and raise an error when it exceeds 24. You could do this using ng-onchange or when the user submits. This answer: Count the number of occurrences of a character in a string in Javascript should help you with counting the commas.

Community
  • 1
  • 1
Mike Feltman
  • 5,160
  • 1
  • 17
  • 38