in my website, I have a slug
function in JavaScript. Which will replace all the special character except @
inn the string with -
. It works. but not giving the desired output. What is wrong with the code?
My function is
function to_slug(string) {
var new_str = string.trim().replace(/[^0-9a-zA-Z@]+/i, '-').toLowerCase();
return new_str;
}
This function works for first two space
strings. that is,
sample shop
will give output sample-shop
but
sample shop hfnbbf
giving output as sample-shop hfnbbf
and
sample shop hfnbbf.hgdsf
giving output as sample-shop hfnbbf.hgdsf
Whay this is happening? please help me.. Thanks in advance