troubleshooting Question

validate texteditor data and add a comma

Avatar of lulu50
lulu50Flag for United States of America asked on
JavaScriptC#AJAXjQueryJSON
6 Comments1 Solution46 ViewsLast Modified:
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 










Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros