1

I am using bootstrap 3.3.7, jQuery 3.1.1 and jQuery-UI 1.12.0 for a form to ask for email and some other details.

For using autocomplete I am using the example shows under

https://jqueryui.com/autocomplete/#multiple

Email looks like this

<div class='form-group row'>
  <label class='col-md-2 control-label'>To....</label>
  <div class='col-md-6'>
    <input type='email' class='form-control inputMail' name='mailTo' required multiple>
  </div>
</div>

As you can see, input is type email and I would like to validate the input.

My problem is the last comma, this input will not be accepted.

Invalid input:

invalid input

But when I remove the last comma by hand it works.

Valid input:

valid input

Have anyone a solution how it works without removing the last comma by hand?

L_J
  • 2,351
  • 10
  • 23
  • 28
Struppi
  • 21
  • 3
  • 1
    Could you not do something on select that would trim the last comma: http://api.jqueryui.com/autocomplete/#event-select – Pete Aug 03 '18 at 13:09
  • Possible duplicate of [JavaScript chop/slice/trim off last character in string](https://stackoverflow.com/questions/952924/javascript-chop-slice-trim-off-last-character-in-string), and https://stackoverflow.com/questions/22369056/remove-comma-to-the-last-values-autocomplete-multiple-select – Pete Aug 03 '18 at 13:20
  • If trimming is not an option you can use your own pattern for the validation by setting the pattern attribute with your own regex. – Mark Baijens Aug 03 '18 at 13:55
  • I know that slice() is a possibility. But I think an own regex will be the best. Thank you – Struppi Aug 03 '18 at 15:37

0 Answers0