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;
}





This client side javascript will validate a Rich Text Field if data entry is required.

JavaScript (Client)
Ken Behrens
May 20, 2015 9:33 AM
Rating
57

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.



1 comment(s)Login first to comment...
Don Deal
(at 11: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.