Results 1 to 2 of 2

Thread: Testing for a maximum length in a field, and regular expression modifiers

  1. #1
    Join Date
    Apr 2008
    Posts
    23

    Default Testing for a maximum length in a field, and regular expression modifiers

    Hey,

    I'm trying to put some limitations on the max length of specific fields. The only way that I could come up with to do this is to use a regular expression, IE:

    Code:
    conditions1 = ":@
    	@TEST@First_Name ~ /^.{0,255}$/s@First Name is too long! 255 chars max, please.@:
    	"
    Is there a better way to do this? I'm just concerned about possible processing overhead of using so many regular expressions (I'm probably going to check 15 or more fields this way).

    I know that there's the MAXSTRING parameter in the php script to set the max possible length of ANY field, which is good, of course; but I was looking for more granularity in this case.

    I did try using a test in the form of

    Code:
    field1#<number
    but that didn't seem to achieve the required effect.

    The regular expression brought up my second question - does it recognize modifiers like /s and /g at the end of the expression (my expression above is using a /s, which will cause the . (dot) metacharacter to also include newlines. It hasn't complained so far, but I haven't tested it to prove / disprove it's working.


    Oops - one more thing. The MAXSTRING doc page states:

    MAXSTRING also limits the size of fields loaded from an INI file, however, this limiting will be removed in a later version of FormMail.
    Is that still true?

    Because it doesn't appear to be applying to my fmcompute1 section, which is 4970 chars. Is fmcompute a special case, or has the .ini field length been lifted? Or is it perhaps a PHP-version-dependent limitation?

    Thanks,

    Aaron
    Last edited by aaron_w; 21-May-2008 at 04:20 PM. Reason: added, corrected stuff

  2. #2
    Join Date
    Dec 2003
    Posts
    3,980

    Default Re: Testing for a maximum length in a field, and regular expression modifiers

    Hi,

    Quote Originally Posted by aaron_w View Post
    I'm trying to put some limitations on the max length of specific fields. The only way that I could come up with to do this is to use a regular expression, IE:

    Code:
    conditions1 = ":@
        @TEST@First_Name ~ /^.{0,255}$/s@First Name is too long! 255 chars max, please.@:
        "
    Is there a better way to do this?
    Not at the moment. The next version of FormMail will have a %length% function in derive_fields, which will allow you to get the length of a field and then use that in a condition (or computations).

    I'm just concerned about possible processing overhead of using so many regular expressions (I'm probably going to check 15 or more fields this way).
    I wouldn't worry too much. 30 years ago regular expressions ran 3 thousand times slower and were still pretty fast!

    Remember, your server is actually parsing and executing the entire FormMail logic (and your Computation Module) and it does that in milliseconds.

    Also, your Computation Module is then interpreted PHP parsing and executing your computations and that happens in milliseconds too.

    So, a few extra hundred microseconds (if that) for each regular expression isn't going to make much difference.

    I did try using a test in the form of

    Code:
    field1#<number
    but that didn't seem to achieve the required effect.
    That's what you can use to test the value of the length field once you've derived it using the new "length" function.

    The regular expression brought up my second question - does it recognize modifiers like /s and /g at the end of the expression (my expression above is using a /s, which will cause the . (dot) metacharacter to also include newlines. It hasn't complained so far, but I haven't tested it to prove / disprove it's working.
    Yes. "s", "i", "m", etc are all available. "g" is only for replacement operations, so it doesn't apply.

    Oops - one more thing. The MAXSTRING doc page states:

    Is that still true?

    Because it doesn't appear to be applying to my fmcompute1 section, which is 4970 chars. Is fmcompute a special case, or has the .ini field length been lifted? Or is it perhaps a PHP-version-dependent limitation?
    Yes, MAXSTRING still affects most fields even in the INI file.

    There are some fields FormMail explicitly does not truncate:
    • conditions (including conditions1, conditions2, etc.)
    • fmcompute (including fmcompute1, fmcompute2, etc.)
    And in the next version, derive_fields too.

    These non-truncating fields are specified in the $SPECIAL_NOSTRIP array in FormMail.
    Last edited by russellr; 26-May-2008 at 12:36 AM. Reason: Ooops...meant 3 thousand not 3 million!
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Testing FormMailEncoder
    By basnyd in forum FormMailEncoder/Decoder
    Replies: 1
    Last Post: 22-Nov-2005, 07:59 PM
  2. Testing enctype and file uploads
    By russellr in forum FormMail Subscription Support
    Replies: 0
    Last Post: 01-Sep-2005, 08:42 PM
  3. Condition - restrict maximum checkboxes
    By tvulucy in forum FormMail Subscription Support
    Replies: 3
    Last Post: 22-Aug-2005, 08:42 PM
  4. Maximum length of CSV file
    By eu4ic in forum FormMail Subscription Support
    Replies: 3
    Last Post: 14-Aug-2005, 12:34 PM
  5. Can "Reply To" EM Field be set to email field
    By CWD in forum FormMail Subscription Support
    Replies: 2
    Last Post: 26-Jul-2005, 04:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •