2

I have input text field (type = string) which should accept number as input but the number format should be validated based on the defined locale code.

var number = '2,110.168';
if locale is en-in, this should be valid
if locale is nl-nl, this is not a valid format as it should be 2.110,168
georgeawg
  • 48,608
  • 13
  • 72
  • 95
kiran gudla
  • 177
  • 1
  • 11

1 Answers1

1

You can use Number.toLocaleString() which returns the "language-sensitive representation" of a number.

If your input is in a form, you can create a custom validator to validate its value.

JoH
  • 514
  • 1
  • 6
  • 16