0

I'm aware that parsing numbers with pure CSS is impossible. But as in my case I know for certain that the input will always be in a specific way, is it possible to change the display of an input field based on the count of characters in it?

e.G. I want '123450' to be displayed as '1,234.50' - or if it were 'abcdef' it should become 'a,bcd.ef'.

So, I would like a rule that says: from right to left: after the second char display a dot, after the fifth and eight char display a comma.

Is that possible?

Example:

<input type="text" class="unformatted" value="123456" />

Should display like

<input type="text" class="formatted" vaulue="1,234.56" />

while still retaining its original value 123456.

Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72

1 Answers1

0

What you're asking is not possible with pure CSS. The smallest you can go with CSS is the single HTML tag, you cannot go deeper than that.
Individual lines of text cannot be selected or altered, as they are seen as a whole by CSS engine.

With a little help from JavaScript, however, this can be easily done.

Mario Cianciolo
  • 1,223
  • 10
  • 17