Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-03
7
Medium Priority
?
47 Views
Last Modified: 2016-10-09
Hi experts

Could you point what must be changed in this regex to accept two decimal places?
regex:/^[0-9]{1,2}([,.][0-9]{1,2})?$/

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.
0
Comment
Question by:Eduardo Fuerte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 29

Expert Comment

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

Author Comment

by:Eduardo Fuerte
ID: 41827023
Hi

It is DOUBLE. But I guess comma is not acceptable in db as decimal separator... Is it configurable at MySQL?
0
 
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:?

^([0-9]{1,2}(?:[,.][0-9]{1,2}))?$

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:

^[0-9]{1,2}(?:[,.][0-9]{1,2})?$
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Accepted Solution

by:
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.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41827082
Hi @Russ

Our messages crossed. I'm going to check.
0
 
LVL 9

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.
1
 

Author Closing Comment

by:Eduardo Fuerte
ID: 41835722
Hi

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

Thanks.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

688 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