-5

I need a regex for a 5 digit integer number with 2 decimals.

These would be correct:

  • 12345.12
  • 09856.99
  • 45123.00

These wouldn't:

  • 123.12
  • 12345.6
  • 98652
Aegwynn
  • 21
  • 1
  • 4

2 Answers2

0

Use this regex it will work

var regex = /^\d{5}\.\d{2}$/;
var num = '23445.09';
console.log(regex.test(num));  // True

var num2 = '12345.6'
console.log(regex.test(num));  // False

Demo : https://jsbin.com/wasefa/edit?html,js,console,output

KrishCdbry
  • 1,049
  • 11
  • 19
0

This would be correct : /^\d{5}\.\d{2}$/

var value = 12345.12;
value.toString().match(/^\d{5}\.\d{2}$/); // ['12345.12']

var value = 98652;
value.toString().match(/^\d{5}\.\d{2}$/); // null
Robiseb
  • 1,576
  • 2
  • 14
  • 17