#4807: Decimal regex doesn't support a case where no leading numbers are used
---------------------------------------+------------------------------------
   Reporter:  [EMAIL PROTECTED]  |                Owner:  adrian    
     Status:  new                      |            Component:  Validators
    Version:  SVN                      |           Resolution:            
   Keywords:                           |                Stage:  Accepted  
  Has_patch:  1                        |           Needs_docs:  0         
Needs_tests:  0                        |   Needs_better_patch:  1         
---------------------------------------+------------------------------------
Comment (by [EMAIL PROTECTED]):

 A second thought is to just try to convert the string to a decimal.  That
 way, we let the Python module do the heavy lifting and we know whether or
 not  something is a decimal from python's perspective which is what we
 really care about.  This may have a small performance hit compared to a
 regex but I bet it isn't too terribly bad.
 
 Something like this:
 {{{
 from decimal import Decimal
 try:
     decimal_value = Decimal(str(field_data))
 except decimal.InvalidOperation
     raise ValidationError, _("Please enter a valid decimal number.")
 
 }}}
 
 Then, use as_tuple to figure out the number of digit and decimal places.
 Is there any reason this would be problematic?

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4807#comment:12>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to