Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

TEST FOR 0 OR ID (length of 11) 14 Oct 2012 15:37 #4479

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
OK,

I needed to to be able to validate a zero value (0) or a valid integer with a max length of 11 digits for a parent_id field in a nested table (like com_categories table) that I'm working on...

This is how:
^([0-9]{1,1}|[1-9]([0-9]{1,10}))$

How it works:
  • The outer parentheses '()' allow separate arguments
  • The pipe '|' denotes an OR statement
  • Square brackets denote acceptable characters
  • Curly braces '{val1, val2}' specify, upper (val2) and lower (val1) length
So, this regex basically says,
  1. IF the first character matches anything between 0 and 9 ([0-9]) and is only 1 digit long ({1,1}) OR (|)
  2. IF the first character matches anything between 1 and 9 ([1-9]) AND any subsequent characters are between 0 and 9 to a total length of 10 and a minimum of 1 then... RETURN TRUE
ELSE
  • RETURN FALSE
  • **N.B.We only check for a length of 10 as we are only checking everything after the first character in the second case. There are 11 in total - the maximum length of ID fields in the DB**

    Hope this Helps!!!

    Gez
    Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

    Please Log in or Create an account to join the conversation.

    Re: TEST FOR 0 OR ID (length of 11) 22 Dec 2012 15:18 #6242

    • JoomGuy
    • JoomGuy's Avatar Topic Author
    • Offline
    • Moderator
    • Moderator
    • Joomla Enthusiast, Lover of Cooking
    • Posts: 1115
    • Thank you received: 195

    audibleid wrote: This is how:

    ^([0-9]{1,1}|[1-9]([0-9]{1,10}))$

    Shortens to by removing extra parentheses & {1,1}:
    ^([0-9]|[1-9][0-9]{1,10})$
    Gez
    Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

    Please Log in or Create an account to join the conversation.

    Re: TEST FOR 0 OR ID (length of 11) 26 Dec 2012 09:24 #6274

    • g1smd
    • g1smd's Avatar
    • Offline
    • Junior Member
    • Junior Member
    • RegEx fiend!
    • Posts: 31
    • Thank you received: 26
    ^([0-9]|[1-9][0-9]{1,10})$

    Yes, that would work, but it simplifies even more:
    ^(0|[1-9][0-9]{0,10})$
    or
    ^(0|[1-9]\d{,10})$
    :woohoo:
    Online since 1996.
    The following user(s) said Thank You: JoomGuy

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    Time to create page: 0.059 seconds

    I jumped and started to work on a demo component... but 2 days later this demo component became the real component. I just showed today the end result to my customer and he turned to me and said... "this is more than I expected"... All of this is because Cook did cut about 70% of my work and provided me more ways to improve the usability of the component. The end result was 17 tables all related between than to generate a full dashboard for the travel agents. Thanks for Cook developers for such great tool. This component would not be possible to be done at short time with all the features in it
    Griiettner (Forum)  

    Get Started