Reputation: 41
i'm looking for jQuery code which will suggest me a URL for new CMS article, based on the Title of article.
Example:
I wrote title: The sky is blue
jQuery autogenerated URL: /the-sky-is-blue/
Upvotes: 0
Views: 276
Reputation: 4433
function slugify(str){
return str.replace(/\s+/g,'-').replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase();
}
var mySlug = slugify("testing the slugify function"); // testing-the-slugify-function
Upvotes: 2
Reputation: 19368
One way without jquery:
var title = text.replace(/\s+/g, '-').toLowerCase();
Upvotes: 0