The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Page 2 -
Strip out all non-numerics except the last decimal
Page 2 - Discuss Strip out all non-numerics except the last decimal in the Regex Programming forum on Dev Shed. Strip out all non-numerics except the last decimal Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 17th, 2013, 12:45 PM
|
|
Contributing User
|
|
Join Date: Jan 2013
Posts: 34
Time spent in forums: 8 h 21 m 20 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by Jacques1 So what solution are you going now with? You cannot have both.
|
Ok thanks,
No idea, the one that works best. But as none works for me, at the moment I am not going with anyone 
|

January 17th, 2013, 12:52 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
I'm saying that it makes no sense (and it's annoying) to have a discussion with two people about two different approaches at the same time.
First decide if you gonna have two input fields or one. Then we can discuss what you need to do to get it working.
Two fields are more robust and easier to handle. A single field requires some work and regex magic.
|

January 17th, 2013, 01:14 PM
|
|
Contributing User
|
|
Join Date: Jan 2013
Posts: 34
Time spent in forums: 8 h 21 m 20 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by Jacques1 I'm saying that it makes no sense (and it's annoying) to have a discussion with two people about two different approaches at the same time.
|
Thats correct, I am open to both, I suppose one looks more professional, but the most important is that it works, as both are understandable for the user.
Maybe itīs better to keep talking about 2 fields in the original post in php forum not to destroy this as the regex solution can be interisting for other and not only for me:
http://forums.devshed.com/php-devel...00t-938128.html
|

January 17th, 2013, 01:36 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
That script I put in my post, when pasted into a PHP interpreter, prints out all 3 correctly formatted prices. Note that it's a PHP script.
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

January 17th, 2013, 01:50 PM
|
|
Contributing User
|
|
Join Date: Jan 2013
Posts: 34
Time spent in forums: 8 h 21 m 20 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by ManiacDan That script I put in my post, when pasted into a PHP interpreter, prints out all 3 correctly formatted prices. Note that it's a PHP script. |
Thanks,
I use php and this does not print out anything for me, only the word test:
PHP Code:
<?php
$a = '1.457,54';
function strip($a) {
{ return preg_replace("/^(.+?)([\.,](\d{2}))?$/e", "str_replace(array(',','.'),'','\\1') . str_replace(',','.','\\2')", $a);
}
echo strip('123,456,78');
#123456.78
echo strip('123,456.78');
#123456.78
echo strip('123.456,78');
#123456.78
echo $a;
}
echo "test";
?>
|

January 18th, 2013, 04:59 PM
|
|
|
|
I think you should just force your user to use only one format (chose what you wish, American or European, and just stick to it): provide an example of how the amount should be formatted, for example either "1234,56" or "1234.56", and just refuse to validate any amount that does not match your format (with just a possible exception if the user enters an amount with neither a dot nor a comma, in which case it can be considered to be a round dollar or euro amount).
There is nothing wrong, in a user interface, to force the user to to something in the correct way if this correct way is explained clearly in the interface, and this is even a very good thing to to if this can prevent any ambiguity, especially when monetary amounts are at stake.
Of course, having two fields is perhaps even better and more robust, but I have seen many applications (including banking interfaces where you have to enter the amount you want to wire) where just one field enforcing strict rules just does the job right.
Last edited by Laurent_R : January 18th, 2013 at 05:04 PM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|