troubleshooting Question

validate texteditor data and add a comma

Avatar of lulu50
lulu50Flag for United States of America asked on
C#JavaScriptjQueryAJAXJSON
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 



Open in new window








ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 6 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 6 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004