Calculate the length of the each variable and matches to the desired value

My script is currently doing two function and I want to add one more as pre the question.

 
echo -en "Enter the logmsg="
read logmsg
logmsg1=${logmsg%%|*};
logmsg_len2=$(echo ${logmsg} | awk '{print $2}');
logmsg_suffix="|";
Char()
{
#echo $logmsg1
echo $logmsg1 | tr ',' '\n' | awk '{if($0~/^D/||/^S/) {print $0" starts"} else {print " Please check your input(e.g. Start it with D or S)";exit;}}'
}
Pipe()
{
if [[  "${logmsg_len2}" != "${logmsg_suffix}" ]]; then
                 echo -e "error use | symbol"
                 exit 1;
     else
   echo "success"
 fi
}
Char
Pipe

This is the complete string which I am using in the script to get the desired results

D0000,D12345,S1234,D12345 | KestrelPrdV2_0.build.177 - svn 141115 tag as V2.0.0.14

Now my script will cut the left part (left from | symbol)
D0000,D12345,S1234,D12345

Now my question is how to calculate the length of the each varibale and also it should not more than 6 i.e. -le 6.Number of variables can be increases or decreases upto infinity.

Please let me know if more information require.

 echo 'D0000,D12345,S1234,D12345 | KestrelPrdV2_0.build.177 - svn 141115 tag as V2.0.0.14' | nawk -F'[,|]' '{for(i=1;i<NF;i++) print $i "->" length($i)}'

Hi ,

Its working fine but here I want one more thing that if length is above 6 than it should be exited otherwise successful.

Thanks in advance

---------- Post updated at 02:08 AM ---------- Previous update was at 01:17 AM ----------

one more thing I can see here that is

echo "D0000,D12345,S1234,D12345 | KestrelPrdV2_0.build.177 - svn 141115 tag as V2.0.0.14" | awk -F'[,|]' '{for(i=1;i<NF;i++) print $i "->" length($i)}';
D0000->5
D12345->6
S1234->5
D12345 ->7

It gives the wrong length of the last variable.

Kindly advise

code is perfect ..
One extra space character is present after "5" in D12345 .. So the length is "7"

Code is perfect but the conditon was that there should be space left and right of the pipe symbol...and one more thing that is if length is above 7 it should be exited.

Please advise