You need to sign in to do that
Don't have an account?
SS Karthick
validation in rich text area data type
Hi folks
Can anyone tell me how to validate if the rich text area has image and html tag
Thanks in advance
Karthick
Can anyone tell me how to validate if the rich text area has image and html tag
Thanks in advance
Karthick
You can form a string within while loop which contains comma seperated HTML tags and then you can check if that string contains img tag as below:
Intranet_News__c obj = [select Story__c from Intranet_News__c where Id = 'a2Nc0000000DL3H'];
string strRichtext = obj.Story__c;
string strTags = '';
while(strRichtext.indexOf('<') > -1 && strRichtext.indexOf('>') > -1)
{
Integer i = strRichtext.indexOf('<');
Integer j = strRichtext.indexOf('>');
string strtobeReplaced = strRichtext.substring(i, j+1);
strTags = (strTags == '') ? strtobeReplaced : strTags + ', '+strtobeReplaced;
strRichtext = strRichtext.replace(strtobeReplaced, '');
}
if(strTags.indexOf('<img>') > -1)
//This means the Rich text field contains image.
Thanks
All Answers
You can form a string within while loop which contains comma seperated HTML tags and then you can check if that string contains img tag as below:
Intranet_News__c obj = [select Story__c from Intranet_News__c where Id = 'a2Nc0000000DL3H'];
string strRichtext = obj.Story__c;
string strTags = '';
while(strRichtext.indexOf('<') > -1 && strRichtext.indexOf('>') > -1)
{
Integer i = strRichtext.indexOf('<');
Integer j = strRichtext.indexOf('>');
string strtobeReplaced = strRichtext.substring(i, j+1);
strTags = (strTags == '') ? strtobeReplaced : strTags + ', '+strtobeReplaced;
strRichtext = strRichtext.replace(strtobeReplaced, '');
}
if(strTags.indexOf('<img>') > -1)
//This means the Rich text field contains image.
Thanks
Thanks