Posted By

jmiller on 05/25/10


Tagged

strip String slug to convert characters


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

knedle
elundmark


Convert to slug


 / Published in: jQuery
 

URL: http://stackoverflow.com/questions/1053902/how-to-convert-a-title-to-a-url-slug-in-jquery

Takes one field and converts the string to a URL-friendly slug in a second field

  1. function convertToSlug(Text) {
  2. return Text.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-');
  3. }
  4.  
  5.  
  6. // Usage:
  7. $("#Name").keyup(function(){
  8. $("#Slug").val(convertToSlug($(this).val()));
  9. });

Report this snippet  

You need to login to post a comment.