mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Field): minus can only be placed on the first char (#6303)
This commit is contained in:
parent
ee599ddcbe
commit
ca827c205e
@ -4,12 +4,16 @@ export function range(num: number, min: number, max: number): number {
|
||||
|
||||
function trimExtraChar(value: string, char: string, regExp: RegExp) {
|
||||
const index = value.indexOf(char);
|
||||
|
||||
if (index > -1) {
|
||||
return value.slice(0, index + 1) + value.slice(index).replace(regExp, '');
|
||||
|
||||
if (index === -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value;
|
||||
if (char === '-' && index !== 0) {
|
||||
return value.slice(0, index);
|
||||
}
|
||||
|
||||
return value.slice(0, index + 1) + value.slice(index).replace(regExp, '');
|
||||
}
|
||||
|
||||
export function formatNumber(value: string, allowDot?: boolean) {
|
||||
|
@ -113,4 +113,5 @@ test('formatNumber', () => {
|
||||
expect(formatNumber('-1.2')).toEqual('-1');
|
||||
expect(formatNumber('-1.2', true)).toEqual('-1.2');
|
||||
expect(formatNumber('-1.2-', true)).toEqual('-1.2');
|
||||
expect(formatNumber('123-')).toEqual('123');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user