htmanning has asked for the wisdom of the Perl Monks concerning the following question:

I know this is simple but... How do I limit the number of characters a string can contain without a space. In other words, I have spambots placing long gibberish strings in a form, and they never include spaces. I need to be able to detect if the field has only one word of 12 characters in a row without a space. If there are two words, one of them can have 12 characters. I also need to detect whether a field has numbers instead of letters. Thanks.

Replies are listed 'Best First'.
Re: Limit long words and numbers
by JavaFan (Canon) on Apr 12, 2012 at 07:08 UTC
    String consisting of 12 non-spaces: /^\S{12}$/. String consisting of at least 12 non-spaces: /^\S{12,}$/. Just numbers: /^[0-9]+$/.
      Really appreciate your help. This worked.
      &error1(banned) if ($organization =~ /^\S{11,}$/);
      Thanks.
Re: Limit long words and numbers
by GrandFather (Saint) on Apr 12, 2012 at 07:08 UTC

    Use a regular expression match. See perlretut.

    True laziness is hard work
Re: Limit long words and numbers
by Anonymous Monk on Apr 12, 2012 at 07:08 UTC

    I know this is simple but...

    Great, fill in the blanks

    #!/usr/bin/perl -- use strict; use warnings; my $input = '...'; my $wantedOutput = '..'; my $actualOutput = limitLongWordsAndNumbers( $input ); if( $actualOutput eq $wantedOutput ){ print "Success!\n"; } else { print "Failure!\n"; } sub limitLongWordsAndNumbers { @_ }