Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:25:41+00:00 2026-05-31T16:25:41+00:00

I am trying to create an SEO-friendly link from the input in a text

  • 0

I am trying to create an SEO-friendly link from the input in a text input box. I do so on the blur event when the cursor leaves the input in question. I can get the text in the input to appear in the desired input (for the link), but my link isn’t hyphenated and special characters are not replaced with hyphens. I am trying to do a global string replace, but the expression expects a string, not a variable. At least from what I can tell. Also, I can’t figure out a better way to match the list of special characters, other than an array and a loop. Can someone help? My desire is to create link like this: http://domain.com/this-is-my-link. Here is my code:

$('#title').blur(function() {   
      var hyphenated;   
      hyphenated = urlTitle($(this).val());             
      $('#link').val(hyphenated);       
});


function urlTitle(text) {       
    var characters = [' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', '_', '{', '}', '[', ']', '|', '/', '<', '>', ',', '.', '?', '--']; 

    for (var i = 0; i < characters.length; i++) {
         var char = String(characters[i]);
         text = text.replace(/char/g, '-');

}           
    text = text.toLowerCase();
    return text;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:25:42+00:00Added an answer on May 31, 2026 at 4:25 pm

    The problem lies in your escaping function:

    text = text.replace(/char/g, '-');
    

    This literally matches “char”. So if you give it I'm building a string out of chars, it will return i'm building a string out of -s.

    If you want to make up a regex expression dynamically using a variable, you’ll need to build it using a string and the RegExp constructor.

    text = text.replace(new RegExp("\\" + char, "g"), '-');
    

    Note that when using this format you do not need to specify the delimiting characters (the forward slashes before and after), and that the flags are passed as the second parameter to the constructor. I also prepended a backslash to escape any special characters you might want to replace.

    Live example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a URL friendly link from a string. Instead of
I'm trying create a box in my Django app that displays text (and possibly
im into SEO and friendly URL's and im trying to create a rule in
I am trying to create a content management system with SEO friendly URLs ..
I am trying create system in which I can login from php and then
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I'm trying create a RCP Application with Eclipse, but I can't get past the
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
I trying create a class derivated from System.Web.UI.Page and in override Render i set
I am trying create a 'live' view where our clients can edit the colors

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.