Welcome, Guest
Username: Password: Remember me

TOPIC: Re: DECIMAL FLD DONT VALIDATE IF NOT FOCUSOUT B4 SAVE

Re: DECIMAL FLD DONT VALIDATE IF NOT FOCUSOUT B4 SAVE 23 Nov 2012 07:58 #5627

  • g1smd
  • g1smd's Avatar
  • Offline
  • Junior Member
  • RegEx fiend!
  • Posts: 31
  • Thank you received: 26
  • Karma: 6
//decima8to2
^(0(\.(0[1-9]|[1-9]\d{0,1}))|([1-9]\d{0,5}(\.\d{0,2})?))?$
This allows 0 values only when followed .01 or greater or any numbers beginning with 1-9 up to 6 digits total followed by optional decimal point + 1 or 2 digits
There's a slight difference between your code and the description.
(\.\d{0,2})?
allows optional decimal point + 0 or 1 or 2 digits so 40.00 could be entered as 40. or as 40 here.

The final ?$ also allows blank input. There's also a set of unnecessary brackets.

Suggest
^( 0(\.(0[1-9]|[1-9]\d{0,1})) | [1-9]\d{0,5}(\.\d{0,2})? )$
or
^( 0(\.(0[1-9]|[1-9]\d{0,1})) | [1-9]\d{0,5}(\.\d{1,2})? )$

If you want to allow people to type .75 instead of 0.75 try:
^( 0?(\.(0[1-9]|[1-9]\d{0,1})) | [1-9]\d{0,5}(\.\d{1,2})? )$

Remove spaces before using.

Regular expressions give you an infinite number of very fine grained possibilities. :)
Online since 1996.
Last Edit: 23 Nov 2012 08:11 by g1smd.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: DECIMAL FLD DONT VALIDATE IF NOT FOCUSOUT B4 SAVE 25 Nov 2012 11:05 #5638

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 68
Hi @g1smd

I thought I'd already replied to this but obviously didn't.

The first regex is the cook default, the one I wanted to replace with the longer one which I believe does fit the requirements I specified doesn't it?

Thanks for pointing out the additional brackets! Will remove although the required parameter on the field prevents the user leaving blank.

Thanks again,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
The following user(s) said Thank You: g1smd

Re: DECIMAL FLD DONT VALIDATE IF NOT FOCUSOUT B4 SAVE 30 Nov 2012 00:02 #5691

  • g1smd
  • g1smd's Avatar
  • Offline
  • Junior Member
  • RegEx fiend!
  • Posts: 31
  • Thank you received: 26
  • Karma: 6
^([1-9]\d{0,1}(\.\d{1,2})?|0\.[1-9]\d{0,1})$
\d{0,1}
simplifies to
\d?
:)
^([1-9]\d?(\.\d{1,2})?|0\.[1-9]\d?)$
Online since 1996.
Last Edit: 30 Nov 2012 00:02 by g1smd.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy
Time to create page: 0.057 seconds

Get Started