Javascript String slug()

Description

Javascript String slug()


String.prototype.slug = function () {
    var arr = this.split(" ");
    var output = arr.join("-");
    return output;
}
function slug() {
var str = document.getElementById("str").value;    
document.getElementById("para").innerHTML = str.slug();
}

Javascript String slug()

// url slug/*www.j  a  v a 2  s  .  c  o  m*/
String.prototype.slug=function(){
   return this.toLowerCase().replace(/\s/g,'-').replace(/[^a-zA-Z0-9]/g,'-').replace(/-{2,}/g,'-').replace(/^-/,'').replace(/-$/,'');
}



PreviousNext

Related