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.098 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started