How to block texts received from numbers that are longer than n digits?
The first step to this would be detecting the length of the phone number.  

This can be done by passing %SMSRF to Test Variable > Type: Length. Test Variable can then output the phone number length as an integer which you can do checks on with an If.  

Once Tasker decides if the message is spam or not, you can then have it hide the notification, etc. (but not delete the message, as Tasker does not have this capability yet)