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.
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.
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!
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.
is working on a reply...