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 859299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:39:46+00:00 2026-05-15T08:39:46+00:00

I am looking for a way to generate a valid tag (string with only

  • 0

I am looking for a way to generate a valid tag (string with only a-z and minus as valid chars) out of a given string.

Just let me show you the code:

<p>
    <label>Tag Title *:</label>
    <input type="text" class="tag_title" name="input_tag_title" value="" />
</p>
<p>
    <label>Tag (A-Z; -) *:</label>
    <input type="text" class="tag" name="input_tag" value="" />
</p>

As soon as Tag title looses focus, the Tag input box shall be filled with a valid string. It should only contain characters a-z (regardless of case) and a minus. But this should only take place if the tag-input is empty. If it is not empty, the entered string (in the tag input field) shall be checked for invalid chars and automatically replace all non-valid characters (replace all non-alphabetical characters with minuses).

I tried it with

$(".tag_title").blur(
    function()
    {
        $(".tag").text = this.value.replace(/[^a-z\-]/g, '_');
    }
);

But that does not work. Any hints?

Thanks!

  • 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-15T08:39:47+00:00Added an answer on May 15, 2026 at 8:39 am

    You need to use .val(...) to change the value of a text input.

    I also used .val() against the .tag_title element (wrapped in a jQuery object) that received the blur event to get the value the user typed.

    Test it out: http://jsfiddle.net/8mqzd/

    $(".tag_title").blur(
        function() {
            var $tag = $('.tag');
            if( $tag.val() == "" ) {
                $tag.val( $(this).val().replace(/[^a-z\-]/g, '-') );
            }
        }
    );​
    

    http://api.jquery.com/val/

    EDIT: Made it so it only replaces if the .tag element is empty (as requested).

    EDIT: As Nick pointed out, your use of this.value to retrieve the value of the element that received the blur was just fine. I changed it to use jQuery’s .val(), but please don’t take from that the idea that you must use .val(). :o)

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

Sidebar

Related Questions

I'm looking for a way to automatically generate source code for new methods within
I'm looking for a way to generate a (fairly) unique (non auto-incrementing) 4-digit string
I'm looking for a way to generate a set of random sided, but regular,
I am looking for a way to generate pseudo random number sequences that will
I'm looking for a way to programatically generate a twitter feed for a .NET
I'm looking for an easy way to generate previews for labels generated as pdfs.
I'm looking for an elegant way to generate a sequence of the rolling average
I am looking for a good, standard way to generate output in my RCP
.NET 4.0 I am looking for the easiest way to generate a Word document
I'm looking for a way to generate pdf files from html In order to

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.