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

The Archive Base Latest Questions

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

(as a follow up to this question: In Jquery AND Rails, how to get

  • 0

(as a follow up to this question: In Jquery AND Rails, how to get visible character count of a string?)

Let’s say you have a string with embedded links and tags like so:

 This string has <a href="http://www.google.com">some links</a> inside it.

Then the visible string to a user is:

 This string has some links inside it.

The full string has 73 characters and the visible just 37 characters.

Let’s say I now want to write a rails validation (custom validation) that checks the visible length of the string. ie:

 validate :string_visible_length

 def string_visible_length
      #some code that verifies the character length of a field named :field_name
 end

Any ideas how to accomplish this? I would need to strip the html tags and then check the character length..

  • 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-25T12:17:41+00:00Added an answer on May 25, 2026 at 12:17 pm

    I think you could use the strip links method in your validation.

    Make helpers available in your model file:

      include ActionView::Helpers
    

    Here’s the validation:

      validate :string_visible_length
    
    private
    
      def string_visible_length
        visible_string = strip_links(self.column_name) # where column_name is the field you need validated
        errors.add(:base, 'Visible string is too long') if visible_string.length > 20 # 20 is whatever length you need
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Follow up to this question . I have the following code: string[] names =
Follow-up to this question: Setting background-color of select options in JQuery I have a
As a follow up to this question , I have a parent entity that
(Note: This is a follow up to my question Can jQuery.getJSON put a domain's
This is a follow up to this question: dropdownlist to combobox I have a
This is a follow-up to this question: Using javascript:function syntax versus jQuery selector to
This is a follow up to a question that was asked yesterday. I have
Follow up to this question about GNU make : I've got a directory, flac
This question is a follow on from this one ... I am binding to
Follow up to this question for Facebook Friends.getAppUsers using Graph API that pulls friends

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.