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

34 lines
954 B
TypeScript
Raw Normal View History

2025-01-13 02:49:20 +00:00
// @ts-nocheck
/**
*
* @param value string number
* @returns true false
*/
// #ifndef APP-IOS || APP-ANDROID
export function isNumeric(value: string | number | undefined | null): boolean {
return /^(-)?\d+(\.\d+)?$/.test(value);
}
// #endif
// #ifdef APP-IOS || APP-ANDROID
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