Could you point what must be changed in this regex to accept two decimal places?

Posted on 2016-10-03
Last Modified: 2016-10-09
Hi experts

Could you point what must be changed in this regex to accept two decimal places?

Open in new window

When using this it accepts correctly only digits with ","   and "."  but when saved to DB table the decimal part is truncated.

Thanks in advacne.
Question by:Eduardo Fuerte
LVL 25

Expert Comment

by:Dr. Klahn
ID: 41826995
Is the database table entry of type integer?

Author Comment

by:Eduardo Fuerte
ID: 41827023

It is DOUBLE. But I guess comma is not acceptable in db as decimal separator... Is it configurable at MySQL?
LVL 20

Expert Comment

by:Russ Suter
ID: 41827037
Not sure what your code is doing that's processing the data but it could have to do with the fact that the decimal part is in a numbered capture group and the whole part is not. Try this:?


This puts the entire expression into a single numbered capture group. If that doesn't work you can try putting the entire expression outside a capture group like this:

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.


Accepted Solution

Eduardo Fuerte earned 0 total points
ID: 41827079
Is just a matter to use str_replace  changing "," by "." before to save, doing that the value is correctly saved at db table.

Author Comment

by:Eduardo Fuerte
ID: 41827082
Hi @Russ

Our messages crossed. I'm going to check.

Expert Comment

by:Brian Tao
ID: 41827478
You have to escape it with a "\" because dot (decimal point) is reserved in Regex. It matches a single character.

Author Closing Comment

by:Eduardo Fuerte
ID: 41835722

The regex I used since the start is OK.
It's a matter of use the correct format  to insert values in MySQL.


Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question