合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
942 B

  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