Merge pull request #80 from geertweening/amount-regex

Amount regex
This commit is contained in:
wltsmrz
2014-05-21 10:57:46 -07:00
2 changed files with 19 additions and 1 deletions

3
.gitignore vendored
View File

@@ -43,3 +43,6 @@ test/config.js
/src-cov
/coverage.html
/coverage
# Ignore IntelliJ files
.idea

View File

@@ -593,8 +593,23 @@ Amount.prototype.invert = function() {
* 25.2 XRP => 25200000/XRP
* USD 100.40 => 100.4/USD/?
* 100 => 100000000/XRP
*
*
* The regular expression below matches above cases, broken down for better understanding:
*
* ^\s* // start with any amount of whitespace
* ([a-z]{3})? // optional any 3 letters
* \s* // any amount of whitespace
* (-)? // optional dash
* (\d+) // 1 or more digits
* (\.(\d*))? // optional . character with any amount of digits
* \s* // any amount of whitespace
* ([a-f0-9]{40}|[a-z0-9]{3})? // optional 40 character hex string OR 3 letters
* \s* // any amount of whitespace
* $ // end of string
*
*/
Amount.human_RE = /^\s*([a-z]{3})?\s*(-)?(\d+)(?:\.(\d*))?\s*([a-f0-9]{40}|[a-z0-9]{3})?\s*$/i;
Amount.human_RE = /^\s*([a-z]{3})?\s*(-)?(\d+)(\.(\d*))?\s*([a-f0-9]{40}|[a-z0-9]{3})?\s*$/i;
Amount.prototype.parse_human = function(j, opts) {
opts = opts || {};