Convert to slug


/ Published in: jQuery
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. });

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.