Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • suzyb 474 posts 932 karma points
    Sep 21, 2011 @ 11:47
    suzyb
    0

    Validating text without including html

    I have a rich text field that I want users to only be able to enter 200 characters into.

    I have used a regular expression to do the validation but am finding it doesn't work correctly.  If I set the regex to limit the characters to 200 no styling can be added if the actual text is close to that limit as the regex checks the html as well as the text that will be displayed.

    If however I set the limit to higher than 200 too many characters can be entered into the field.

    Does anyone know a regex that will validate the length of text but ignore any html tags.

  • Barry Fogarty 493 posts 1129 karma points
    Sep 21, 2011 @ 13:57
    Barry Fogarty
    0

    I don't have a regex I'm afraid, but what you could try is building a custom datatype and utilising the HTML agility pack:

    http://htmlagilitypack.codeplex.com

    That way you can extract the InnerText and to a character count on it:

    var document =newHtmlDocument();
    document
    .LoadHtml("...");
    document
    .DocumentNode.InnerText;

    If you want to persist with a regex I woukld suggest posting your current code on StackOverflow and get the regex bods to answer!

     

  • suzyb 474 posts 932 karma points
    Sep 21, 2011 @ 20:32
    suzyb
    0

    I've asked on stack overflow.  The site is more or less live now so building a custom datatype and getting it onto the server is going to be an issue.

Please Sign in or register to post replies

Write your reply to:

Draft