cxc-szcx-uniapp/uni_modules/lime-shared/isNumeric/index.ts

34 lines
942 B
TypeScript
Raw Normal View History

2024-09-14 02:26:50 +00:00
// @ts-nocheck
/**
*
* @param value string number
* @returns true false
*/
2025-02-11 01:34:29 +00:00
// #ifndef UNI-APP-X && APP
2024-09-14 02:26:50 +00:00
export function isNumeric(value: string | number | undefined | null): boolean {
return /^(-)?\d+(\.\d+)?$/.test(value);
}
// #endif
2025-02-11 01:34:29 +00:00
// #ifdef UNI-APP-X && APP
2024-09-14 02:26:50 +00:00
import {isNumber} from '../isNumber';
import {isString} from '../isString';
export function isNumeric(value : any|null) : boolean {
if(value == null) {
return false
}
if(isNumber(value)) {
return true
} else if(isString(value)) {
// const regex = "-?\\d+(\\.\\d+)?".toRegex()
const regex = new RegExp("^(-)?\\d+(\\.\\d+)?$")
return regex.test(value as string) //regex.matches(value as string)
}
return false
// return /^(-)?\d+(\.\d+)?$/.test(value);
}
// #endif