Knowledge Base > RichTextBox > Implementation Knowledge Base Home | Login
Search the Knowledge Base
 
Start Search in the Following Category

Using the ASP Regular Expression Validator for RichTextBox Content

If you use an ASP Required Field Validator to validate RichTextBox content you may find that it validates even when there is no text displayed in the editor. This is due to HTML fomatting tags being used to validate even when there are no text elements within the tags. For example the following will validate fine with the Required Field Validator -

 

<p><font face="Trebuchet MS" color="darkblue" size="4"><font style="BACKGROUND-COLOR: lawngreen"></font></font>&nbsp;</p>

 

These tags will still be there even if the user removes all the text from the editor. To validate the actual content so that it does include text elements we can create an ASP Regular Expression Validator like the following –

 

<asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server"

ErrorMessage="Please input some content." ControlToValidate="RichTextBox1"

ValidationExpression=".*>\w+<.*"></asp:regularexpressionvalidator>

 

If a text element/content is input between the tags e.g Name5 then the validation succeeds. The HTML fragment above would fail however as there is a no text between the tags.

 

For the Developer's Guide to .NET Framework Regular Expressions.

Please see -http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcomregularexpressions.asp




Did this page answer your question? If not, try the Forums or contact us.

Copyright Richer Components 2005. All rights reserved. No part of this article may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording or otherwise) without the prior written permission of Richer Components. All brand names and product names used in this article are trade names, service marks, trademarks, or registered trademarks of their respective owners.


Knowledge Base Software - myKB.com