javascript - How to convert a Title to a URL slug in jQuery? -


I am working on an app in CodeIgniter, and I am trying to create a field on a form, By default, the URL slug What I want to do, breaks punctuation, converts it to lowercase, and changes the space with hyphens, so for example, Shane's Rib Shake will become a sans-rib-flick.

Even what I have so far lowercase was easy, but the replacement does not work at all, and I do not have any idea of ​​removing the punctuation marks:

  $ ("# restaurant_name"). Keyp (function () {var text = $ (this) .val (); Text = Text.toLowerCase (); Text = Text.replace ('/ \ s / g', '-'); $ ("# Restaurant_Slug ") Val (text);}); I do not know where the word 'Slug' came from, but here we go here. :  
  function convert slogan (text) {return text .toLowerCase () .replace (/ / g, '-') .replace (/ [^ \ w -] + / g, '' ); }  

The first position will change the hyphen to an empty space, in the second place will not remove an alphanumeric, underscore, or hyphen.

If you do not want to "like things - this" by changing it to "---" instead you can use it instead:

  Function convertTauslog (text) {return text .toLowerCase () .replace (/ [^ \ w] + / G, '') .replace (/ + / g, '-'); }  

This will remove hyphen (but not spaces) in the first place, and in the second place it will be summarized continuously in the same hyphen.

So "like" it comes in the form of "as-it".


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -