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

TOPIC: VALIDATE DECIMAL (MUST BE POSITIVE)

[HOW T0] VALIDATE DECIMAL (MUST BE POSITIVE) 17 Nov 2012 18:53 #5438

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Requirements:
  1. enforce 2 digits after the decimal point - auto insert (.)00 if a regular integer entered e.g a 1 becomes 1.00
  2. The products should always have a height and width > 0 so 0.01 is the smallest value the user should be able to input
  3. maximum of 6digits before the decimal point
  4. If a user enters .1 it should transform value to 0.10
  5. If a user enters .12 it should transform value to 0.12
********EDIT*************
USE DECIMAL FIELD TO AUTO INSERT THE DECIMAL POINT & TRAILLING DIGITS

*******************************
These values are allowed/disallowed:
AllowedDisallowed
0.010.00
123456.99012345.00
12.0012.0
119.75119.759
99.0099

Here's what I settled on for my custom regex:
^(0(\.(0[1-9]|[1-9]\d))?|([1-9]\d{0,5}\.\d{2}))$
handler: price6pt2
field type: string
Length (property): 9 (to include decimal point '.')

Thanks @g1smd for all the help!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 22 Nov 2012 14:34 by JoomGuy.
The administrator has disabled public write access.

Re: [HOW T0] VALIDATE DECIMAL (MUST BE POSITIVE) 18 Nov 2012 17:28 #5472

  • g1smd
  • g1smd's Avatar
  • Offline
  • Junior Member
  • RegEx fiend!
  • Posts: 31
  • Thank you received: 26
  • Karma: 6
audibleid wrote:
^(0(\.(0[1-9]|[1-9]\d))?|([1-9]\d{0,5}\.\d{2}))$
  1. If a user enters .1 it should transform value to 0.10
  2. If a user enters .12 it should transform value to 0.12
These values are allowed/disallowed
A Regular Expression cannot "transform" a value. It can only say whether what was entered matches the pattern, or not.
You'll need some extra code if you want to allow a user to enter 1 and it be changed to 1.00 or enter .1 and it be changed to 0.10, etc.
Online since 1996.
The administrator has disabled public write access.

Re: [HOW T0] VALIDATE DECIMAL (MUST BE POSITIVE) 22 Nov 2012 14:31 #5622

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

Sorry, that was a mistake in copying my requirements to the end of the thread to go with the updated expression!

Thanks for pointing it out.

BTW - if you want to auto add trailing digits past the decimal point even if they aren't entered, use a DECIMAL type field. The precision parameter handles the auto insertion of this.

Best,

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
  • Page:
  • 1
  • 2
Time to create page: 0.075 seconds

Get Started