Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag 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








Avatar of leakim971
leakim971
Flag of Guadeloupe image

could you setup/provide a test page?

Avatar of lulu50

ASKER

Yes, I'm putting it together right now

Avatar of lulu50

ASKER

leakim971

Thank you so much

I had it working just fine because I was using a textarea
but I had to change my code to a texteditor and that when the problem started.

Please see the attached documents
 TestPage.html
jodit.min.css
jodit.min.jsjquery-ui.jsjquery-ui.js
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

Good Morning leakim971,

yes I was able to do it on the server side.

Thank you so much for all your help

Enjoy your day!!!
you welcome!
Have a nice day too