npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

xd-datacheck

v1.0.0

Published

通用校验方法

Readme

通用校验方法


用法

安装

npm install xd-datacheck --save

引用

var check = require("xd-datacheck"); // 在头部引入

方法

1、IsNotEmpty()

// 验证字符串非空

check.Validator.IsNotEmpty(val); // 空为false。

2、IsFalse()

// 验证变量的Boolean类型,当为0、null、undefined、''、""、false、NaN 为false

check.Validator.IsFalse(val);

3、IsNumber()

// 验证数字(double类型) [可以包含负号和小数点]

check.Validator.IsNumber(val); // 数字为true

4、IsInteger()

// 验证整数

check.Validator.IsInteger(val);

5、IsIntegerNotNagtive()

// 验证非负整数

check.Validator.IsIntegerNotNagtive(val);

6、IsIntegerPositive()

// 验证正整数

check.Validator.IsIntegerPositive(val);

7、IsDecimal()

// 验证小数

check.Validator.IsDecimal(val);

8、IsEnglishCharacter()

// 验证只包含英文字母

check.Validator.IsEnglishCharacter(val);

9、IsIntegerAndEnglishCharacter()

// 验证只包含数字和英文字母

check.Validator.IsIntegerAndEnglishCharacter(val);

10、IsChineseCharacter()

// 验证只包含汉字

check.Validator.IsChineseCharacter(val);

11、IsIntegerLength()

// 验证数字长度范围(数字前端的0计长度)[若要验证固定长度,可传入相同的两个长度数值]

check.Validator.IsIntegerLength(val, lengthBegin, lengthEnd);

12、IsStringInclude()

// 验证字符串包含内容

check.Validator.IsStringInclude(val, withEnglishCharacter, withNumber, withChineseCharacter); 
// 参数内容分别为: 校验值、是否包含英文字母(是true)、包含数字?(是true)、包含汉字?(是true)

13、IsStringLength()

// 验证字符串长度范围 [若要验证固定长度,可传入相同的两个长度数值]

check.Validator.IsStringLength(val, LengthBegin, LengthEnd);

14、IsStringByteLength()

// 验证字符串字节数长度范围 [若要验证固定长度,可传入相同的两个长度数值;每个汉字为两个字节长度]

check.Validator.IsStringByteLength(val, LengthBegin, LengthEnd);

15、IsDateTime()

// 验证日期 [只能验证日期,不能验证时间]

check.Validator.IsDateTime(val);

16、IsTelePhoneNumber()

// 验证固定电话号码 [3位或4位区号;区号可以用小括号括起来;区号可以省略;区号与本地号间可以用减号或空格隔开;可以有3位数的分机号,分机号前要加减号]

check.Validator.IsTelePhoneNumber(val);

17、IsMobilePhoneNumber()

// [可匹配"(+86)013325656352",括号可以省略,+号可以省略,(+86)可以省略,11位手机号前的0可以省略;11位手机号第二位数可以是3、4、5、6、7、8、9中的任意一个]

check.Validator.IsMobilePhoneNumber(val);

18、IsPhoneNumber()

// 验证电话号码(可以是固定电话号码或手机号码)

check.Validator.IsPhoneNumber(val);

19、IsZipCode()

// 验证邮政编码

check.Validator.IsZipCode(val);

20、IsEmail()

// 验证电子邮箱 [@字符前可以包含字母、数字、下划线和点号;@字符后可以包含字母、数字、下划线和点号;@字符后至少包含一个点号且点号不能是最后一个字符;最后一个点号后只能是字母或数字]

check.Validator.IsEmail(val);

21、IsURL()

// 验证网址(可以匹配IPv4地址但没对IPv4地址进行格式验证;IPv6暂时没做匹配)[允许省略"://";可以添加端口号;允许层级;允许传参;域名中至少一个点号且此点号前要有内容]

check.Validator.IsURL(val);

22、IsIPv4()

// 验证IPv4地址 [第一位和最后一位数字不能是0或255;允许用0补位]

check.Validator.IsIPv4(val);

23、IsIPv6()

// 验证IPv6地址 [可用于匹配任何一个合法的IPv6地址]]

check.Validator.IsIPv6(val);

24、IsIDCard()

// 验证身份证号码格式 [一代身份证号码为15位的数字;二代身份证号码为18位的数字或17位的数字加字母X]

check.Validator.IsIDCard(val);

25、IsLongitude()

// 验证经度

check.Validator.IsLongitude(val);

26、IsLatitude()

// 验证纬度

check.Validator.IsLatitude(val);

27、IsPort()

// 验证端口号, 可设置端口范围, begin和end不设置则默认端口号为0~65535

check.Validator.IsPort(val, begin, end); // 参数:端口值、起始值(整型)、结束值(整型)。