in reply to Re^5: Tweak for my Perl Regex that screens for digits only
in thread Tweak for my Perl Regex that screens for digits only

Aborting with a not so subtle err msg would be the way to go.
Point would be that legit users prob would follow directions, (well, fairly well) and the more time spammers have to waste reading and responding to windy err msg's the better!
I've not used substr, how can it be written to generate an err msg if the length exceeds X chars?
Thx, Mike
  • Comment on Re^6: Tweak for my Perl Regex that screens for digits only

Replies are listed 'Best First'.
Re^7: Tweak for my Perl Regex that screens for digits only
by Roy Johnson (Monsignor) on Jan 26, 2006 at 15:52 UTC
    You wouldn't use substr to generate an err msg. You'd check length of whatever variable shouldn't be too long, and if it exceeded your limit, you'd have the program die or just not call the code that inserts the information into your data store, and generate a page that informs the user that the data they entered was rejected.
    if (length($var) > 30) { # Generate rejection message } else { # Insert data # Generate success message }

    Caution: Contents may have been coded under pressure.
      THANKS ROY!
      You've stated what I meant to say in my wish to force the user to enter only up to some char limit with perl and the code you wrote slips in to my existing "format" of error checking and error (page) generation.

      The code you supplied is exactly what I need for ALL of my forms providing customized data input printed to web pages such as listing events and sent by eMail where field lenght needs to be within limits for formatting or spam containment/resistance or to just enforce brevity on users.
      Thanks again!
      Gratefully,
      Mike