I'm trying to create mask for optional negative decimal number.
This doesn't work: https://stackblitz.com/edit/angular-9mdtqs
Any symbol can be written to the first place. optional boolean option does nothing
@Yokhtop Hey, what do you mean with "optional negative decimal number"? Can you give actual and expected results
@ValeriaKochegarova
I'm trying to set signed number mask, it may be negative or positive.
<input mask="V0*.00"
[patterns]="customPatterns"
[dropSpecialCharacters]="false">
customPatterns = {
'V': {pattern: new RegExp('-?')},
'0': {pattern: new RegExp('[0-9]')}
}
The solution is from here: How to mask optionally negative number?
Actual result:
Any symbol can be written to the first place, not only '-'.
When number is positive it doesn't accept the decimal separator after the first symbol, for example:
1.23 doesn't work.
12.34 works fine.
Expected result:
First place accepts only number or -. Input accepts numbers like 1.23
@Yokhtop you should write in component:
customPatterns = 'V': { pattern: new RegExp('-') };
@ValeriaKochegarova Thanks, but anyway it doesn't work. See updated stackblitz example above.
@Yokhtop add in your component :" '0': { pattern: new RegExp('[0-9]')" and summary you will have smth like this:
customPatterns = { 'V': { pattern: new RegExp('-') } ,
'0': { pattern: new RegExp('[0-9]')
}
};
@ValeriaKochegarova The pattern above is always negative number, but I'm trying to create a mask, that accepts negative numbers as well as positive numbers.
@Yokhtop please update new mask version and add in your component
customPatterns = {
V: { pattern: new RegExp("-?") },
0: { pattern: new RegExp("[0-9]") }
};
@ValeriaKochegarova, see updated example.
https://stackblitz.com/edit/angular-9mdtqs
Why is this closed? I'm seeing the same issue... Check out his stackblitz link
I'm having the same issue right now, the 'V': {pattern: new RegExp("-"), optional: true} doesn't work.
@ramzanh Did u find any solution?
This seems to work as a workaround:
customPatterns = {
'0': { pattern: new RegExp('-|[0-9]') },
'9': {
pattern: new RegExp('[0-9]')
}
};
<input mask="09*.99"
[patterns]="customPatterns"
[dropSpecialCharacters]="false">
optional flag is not working. Problem is actual. Any solutions?
Most helpful comment
Why is this closed? I'm seeing the same issue... Check out his stackblitz link