Advertisement
enkuso

slugify (JS)

Dec 13th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Transform text into a URL slug: spaces turned into dashes, remove non alnum
  3.  * @param string text
  4.  */
  5. function slugify(text) {
  6.     text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
  7.     text = text.replace(/-/gi, "_");
  8.     text = text.replace(/\s/gi, "-");
  9.     return text;
  10. }
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement