Avatar of lulu50
Flag for United States of America

asked on 

validate texteditor data and add a comma


I have a text editor where I need to validate that the user have separated each value with a comma.
if the user did not add the comma, the system will add it for them.

How can I validate that the user have added a comma between each <p></p> 
accept the last one?

This what displays in the ItemList text editor
$('#ItemList').val("<p>333</p><p>444</p><p><span style="color: rgb(255, 0, 0);"><strike>555</strike></span></p><p><span style="color: rgb(255, 0, 0);"><strike>333</strike></span></p><p>333</p>") 

This is what I want it to display 
$('#ItemList').val("<p>333,</p><p>444,</p><p><span style="color: rgb(255, 0, 0);"><strike>555,</strike></span></p><p><span style="color: rgb(255, 0, 0);"><strike>333,</strike></span></p><p>333</p>");

  function validateGroupForm() {
        var returnVal = 0;
        if ($("#ItemList").val() == '') {
            returnVal = 1;
        if (returnVal == 1) {
            return false;
        else {
            var str = $('#ItemList').val();
            if (str.indexOf(", ") < 0)
                str = $('#ItemList').val().replace(/(?:\r\n|\r|\n|\s)/g, ', ');
            if (str.lastIndexOf(", ") == str.length - 2)
                str = str.substring(0, str.length - 2);
            return true;

Thank you 

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon