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

TOPIC:

NUMBER RANGES - No leading Zero 25 Sep 2012 15:03 #3977

  • JoomGuy
  • JoomGuy's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Range: 1-200 - suggested handler intrange1to200
^([1-9]|[1-9][0-9]|[1][0-9][0-9]|20[0-0])$
Range: 1-100 - suggested handler intrange1to100
^([1-9]|[1-9][0-9]|100)$
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: NUMBER RANGES - No leading Zero 09 Nov 2012 15:22 #5172

  • g1smd
  • g1smd's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • RegEx fiend!
  • Posts: 31
  • Thank you received: 26
^([1-9]|[1-9][0-9]|[1][0-9][0-9]|20[0-0])$
[1] simplifies to 1 - you only need a character group if there's more than one character.

[0-0] might crash the RegEx parser. This simplifies to '0'.

[0-9] can usually be expressed as \d if your RegEx is allowed in PCRE format, and this aids readability, a [x-y] group being used only when it is not the full 0 to 9 range. If you can only use POSIX, you'll have to stick to [0-9] notation.


Try:
^([1-9]|[1-9]\d|1\d\d|200)$
However, the part [1-9]|[1-9]\d is "1 to 9 OR 1 to 9 plus a digit"

"10 to 99" is just "1 to 9 plus another digit".

The expression can be compressed, i.e. "1 to 9 plus optional digit": [1-9]\d?


So, 1 to 200 is:
^([1-9]\d?|1\d\d|200)$
( 1 to 9 and 10 to 99 | 100 to 199 | 200 )

Often the problem that needs to be solved can be defined in a different way leading to a much simpler pattern. :)


Oh, and 1 to 100 is:
^([1-9]\d?|100)$
( 1 to 9 and 10 to 99 | 100 )
Online since 1996.
The following user(s) said Thank You: JoomGuy

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

Last edit: by g1smd. Reason: Add note about PCRE and POSIX.
  • Page:
  • 1
Time to create page: 0.377 seconds

This is what you call a component builder. I was able to master using this in a very short time and the resulting component works like a charm. Not just a basic component builder but a fully working component builder with forms fields tables all ready to go. You can make the list and item views to display in the front and back end. Also there is a great forum just starting to evolve and I'm sure this will grow very rapidly when you all realise how good this tool is.
Kevin (JED)

         

Get Started