For WPF control TextEdit from DevExpress15.2, I need an input mask for a fractional number (preferably a given integer / fractional part width), and never displaying the fractional separator character if the user does not write it.
The standard version of the numeric Numeric mask like n not satisfied with the fact that even if we enter an integer, the fractional part separator is still displayed at the end.
Setting MaskUseAsDisplayFormat="False" MaskSaveLiteral="False" values MaskUseAsDisplayFormat="False" MaskSaveLiteral="False" did not give such a result.

I decided to implement it using regular expressions as for a fractional number, thus:

 [-+]?\d{1,32}[.,]?\d{0,6} 

(we do not write special characters for the beginning / end of the line, since they are already implied in DevExpress; in case of entering an incorrect fraction separator character, I have a validation of values)

The problem is that it should skip values ​​like ( 120,345 , 102,345 , 0,123 ) and at the same time DO NOT skip like 012,345 - i.e. A mask is required for a fractional number NOT starting with 0 if there are other digits in the integer part.

Tell me how to win :) not necessarily regular.

  • one
    Try ^[-+]?(?!0+[1-9])\d{1,32}[.,]?\d{0,6}$ - Wiktor Stribiżew
  • @ WiktorStribiżew for some reason DX considers it to be syntactically erroneous: (and without the beginning / end of the line, too - Alias
  • Then regulars will not help you. Without a preview block, forward or backward, it will not be possible to apply the condition at the same time and limit the number of entered digits. - Wiktor Stribiżew
  • @ WiktorStribiżew I think you didn’t understand my remark about special characters ^ , $ - they are automatically applied in the input control mask, you just don’t need to write them explicitly. - Alias
  • one
    Everything rests on a specific engine and implementation of masking. My regular works . - Wiktor Stribiżew

1 answer 1

 ^[-+]?(0|[1-9]\d{0,31})([.,]\d{1,6})?$ 

Check:

 input { box-sizing: border-box; width: 100%; border: 1px solid; outline: none; } :valid { border-color: green; } :invalid { border-color: red; } 
 <input pattern="^[-+]?(0|[1-9]\d{0,31})([.,]\d{1,6})?$" autofocus>