index.ts 942 B

123456789101112131415161718192021222324252627282930313233
  1. // @ts-nocheck
  2. /**
  3. * 检查一个值是否为数字类型或表示数字的字符串
  4. * @param value 要检查的值,可以是 string 类型或 number 类型
  5. * @returns 如果值是数字类型或表示数字的字符串,则返回 true;否则返回 false
  6. */
  7. // #ifndef UNI-APP-X && APP
  8. export function isNumeric(value: string | number | undefined | null): boolean {
  9. return /^(-)?\d+(\.\d+)?$/.test(value);
  10. }
  11. // #endif
  12. // #ifdef UNI-APP-X && APP
  13. import {isNumber} from '../isNumber';
  14. import {isString} from '../isString';
  15. export function isNumeric(value : any|null) : boolean {
  16. if(value == null) {
  17. return false
  18. }
  19. if(isNumber(value)) {
  20. return true
  21. } else if(isString(value)) {
  22. // const regex = "-?\\d+(\\.\\d+)?".toRegex()
  23. const regex = new RegExp("^(-)?\\d+(\\.\\d+)?$")
  24. return regex.test(value as string) //regex.matches(value as string)
  25. }
  26. return false
  27. // return /^(-)?\d+(\.\d+)?$/.test(value);
  28. }
  29. // #endif