Sunday, January 1, 2012

Javascript Regular Expression to match a comma delimited list

This method uses the JavaScript String's match() method to parse a comma delimited list and show its content in a Panel control.

Give it a try here

function ParseList(list) {
    var reg = list.match(/\w+(,\w+)*/g);
    document.getElementById("pnl").innerHTML = "Total length:" + reg.length + "<br />";
    for (var i = 0; i < reg.length; i++) {
        document.getElementById("pnl").innerHTML += "Token:\'" + reg[i] + "\'<br />";

Hire Me

Follow me on Facebook

Follow me

Do you find this Blog helpful?

Follow by Email

About Me

My Photo
Expert Senior Software Developer

Microsoft Business Card