Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
ECMAScript (JavaScript)

/
^-?\d{1,3}(?:(?:,\d{3}){0,4}(?:\.\d{1,2})|(?:(?:\s\d{3}){0,4}|(?:\d{0,12}))(?:[.,]\d{1,2})?)$
/
gm

Description

Validates that a given string is a number of up to 15 integer digits and up to 2 decimal digits. Group separators could be either comma or space class but can't be mixed. Decimal separator could be either comma (if comma was not a group delimiter) or dot.

This variation uses small captures for mode detection (instead of back references)

v5 fixes a little bug when , is used as group separator and , was still accepted as decimal separator v6 is ECMAScript compatible

Submitted by BkQc - a year ago (Last modified a year ago)