You can do this with regex easily:
on $@*:text:$(/(.){ $+ %limit $+ }/iS):#:ban -ku300 # $nick 2 Excess code/Long text detected - Banned! : 5min
Although I think you should exclude the space, which needn't be counted toward the limit.