I am creating CMS news sections with several fields, but the Title and Link URL fields are especially important for this issue. When the user enters the title of the article, I want Javascript / jQuery to replace the text from the Title field and create a “clean” URL fragment, removing any spaces and strange characters with dashes (-).
eg.
Chris FUN new article (title)
kris-fun-new-article (URL Link)
Here is the code, but I can't figure out how to replace a few spaces and special characters
$ ('# title'). keyup (function () {
var ref = $ (this) .val (). toLowerCase (). replace ('\', '-');
$ ('# reference'). val (ref);
});
In addition, as in the title “Chris' New Article,” the regular expression should replace “Chris” (quote and space) with “chris” (one stroke). Essentially, find out if there are two special characters next to each other, and replace them with one dash. DO NOT like this "kris - fun-new-article".
Thank you in advance
Torez source
share