Skip to content

支持任意 JavaScript 环境或框架

类型、正则判断

类型判断

is

判断某值的类型

接收两个参数,第一个 val,第二个 type,返回值 true(该值是该类型)、false(该值非该类型),返回值类型为 boolean

参数属性说明类型
val需要判断的值unknown
type需要判断值的类型string

isNumeric

检查一个值是否为数字,可以是数字,也可以是代表有效数字值的字符串

typescript
isNumeric(123) // true
isNumeric('123') // true
isNumeric(123.45) // true
isNumeric('123.45.6') // false