Validate Rich Text Field


var richCKEditor = CKEDITOR.instances["#{id:inputRichText1}"]; 
// Need to test for 2 possible strings if the RTF is empty
// RegEx tests the initial empty value
var RegEx = /<.+?><.+?>.{5}<.+?><.+?>/;
// RegEx2 test for an empty value if RTF had some text that was removed
var RegEx2 =/<.+?>.{6}<.+?>/;
var BodyText = richCKEditor.getData();
// Uncomment to see the character string and length to test for
// XSP.alert("Text: " + BodyText + " Length: " + BodyText.length);
// Need to test the length so that we do not indicate an error even if something was entered
if((RegEx.test(BodyText) || RegEx2.test(BodyText)) && BodyText.length < 81){
	XSP.alert("Please enter some text");
	return false;
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
2 comment(s)Login first to comment...
Alice Smith
(at 04:37 on 27.09.2017)
Thanks! I really appreciate your effort helping me.
https://www.paisa.co/credit-card
Don Deal
(at 10:39 on 19.04.2016)
It didn't work for me, but maybe I'm not using it right. I tried using this under a Submit/Save button with nothing included in the RTF, however both regular expression tests return false, allowing the form to be submitted with nothing entered in the RTF.