Regular Expressions 101

Community Patterns

1...34567...283

Decimal up to 15.2 digits in French and English culture

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 - 8 months ago (Last modified 8 months ago)