Avatar of lulu50
lulu50
Flag for United States of America

asked on 

validate texteditor data and add a comma

Hi,

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() {
         debugger;
        var returnVal = 0;
  
        if ($("#ItemList").val() == '') {
            $('#ValidateItemList').show();
            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);
            $('#ItemList').val(str);
            $('#GroupForm').submit();
            return true;
        }
    }




Thank you 



Open in new window








C#JavaScriptjQueryAJAXJSON

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon