[Solved] Regex – validate decimal number – max 50 digits excluding decimal | decimal optional | any no. of digits allowed before or after decimal [closed]


Is that what you want?

^(?:\d{1,50}|(?=.{3,51}$)\d+\.\d+)$

Demo & Explanation

var test = [
    '12345678901234567890123456789012345678901234567890', '12345.123456789012345678901234567890123456789012345',
    '123456.7890',
    '123456789012345678901234567890123456789012345678901',
    '12345678901234567890123456789012345678901234567890.1'
];
console.log(test.map(function (a) {
  return a+' :'+/^(?:\d{1,50}|(?=.{3,51}$)\d+\.\d+)$/.test(a);
}));

2

solved Regex – validate decimal number – max 50 digits excluding decimal | decimal optional | any no. of digits allowed before or after decimal [closed]