I try to build a custom RegExp
pattern for allowing only numbers on input, besides if some letters were inputted after these numbers it should allow them. BUT not only in case if no numbers were inputted before letters.
So I make a tiny regexp, but it even allows k
and m
letters on input without any numbers on the beginning. That's bad...
Can someone tell me where am I wrong?
Example:
const matchPattern = new RegExp(/[^0-9(k|m)?]$/, 'gi')
'2323'.match(matchPattern) - // true
'23234k'.match(matchPattern) - // true
'23234m'.match(matchPattern) - // true
'k'.match(matchPattern) - // true, BUT should be false
'm'.match(matchPattern) - // true, BUT should be false