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 🙏

© 2026 – Pkg Stats / Ryan Hefner

yu-validate-utils

v1.0.0

Published

A comprehensive JavaScript validation library with common form validation rules

Readme

Validate Utils

一个功能完整的JavaScript校验库,包含常用的表单验证规则。

功能特性

  • 🚀 轻量级,无外部依赖
  • 📦 支持多种模块格式(UMD、ES Module、CommonJS)
  • 🔧 模块化设计,按需引入
  • ✅ 包含50+常用校验函数
  • 🎯 支持空值校验(空值返回true)

安装

npm install yu-validate-utils

使用方法

ES Module

import { isIP, isMobilePhone, isEmail } from 'yu-validate-utils'

// 校验IP地址
console.log(isIP('192.168.1.1')) // true
console.log(isIP('256.1.1.1')) // false

// 校验手机号
console.log(isMobilePhone('13812345678')) // true
console.log(isMobilePhone('12812345678')) // false

// 校验邮箱
console.log(isEmail('[email protected]')) // true
console.log(isEmail('invalid-email')) // false

CommonJS

const { isIP, isMobilePhone, isEmail } = require('yu-validate-utils')

// 使用方式相同

浏览器

<script src="dist/index.js"></script>
<script>
  console.log(ValidateUtils.isIP('192.168.1.1')) // true
</script>

API 文档

字符串相关

  • isAlpha(str) - 校验纯英文字母
  • isAlphanumeric(str) - 校验英文字母和数字
  • isAscii(str) - 校验ASCII字符
  • isBase64(str) - 校验Base64编码
  • isBoolean(str) - 校验布尔值
  • isEmail(str) - 校验邮箱
  • isLowercase(str) - 校验全小写
  • isUppercase(str) - 校验全大写
  • isLength(str, options) - 校验字符串长度
  • isChineseOnly(str) - 校验纯中文字符
  • hasChinese(str) - 检查是否包含中文字符
  • isAccount(str) - 校验账户名
  • isChineseEnglishNumberDash(str) - 校验中文、英文、数字、下划线、短线
  • isSlug(str) - 校验URL slug

数字相关

  • isInt(str) - 校验整数
  • isFloat(str) - 校验浮点数
  • isNumeric(str) - 校验纯数字
  • isPositiveInt(str) - 校验正整数
  • isNegativeInt(str) - 校验负整数
  • isNonNegativeInt(str) - 校验非负整数
  • isPositiveNumber(str) - 校验正数
  • isNegativeNumber(str) - 校验负数
  • isDecimal(str, maxDecimals) - 通用小数位数校验
  • isOneDecimal(str) - 校验1位小数
  • isTwoDecimal(str) - 校验2位小数
  • isThreeDecimal(str) - 校验3位小数
  • isTwoDigit(str) - 校验两位正整数

网络相关

  • isIP(str) - 校验IP地址
  • isIPv4(str) - 校验IPv4地址
  • isIPv6(str) - 校验IPv6地址
  • isURL(str) - 校验URL
  • isDomain(str) - 校验域名
  • isPort(str) - 校验端口号
  • isMACAddress(str) - 校验MAC地址

联系方式相关

  • isMobilePhone(str) - 校验手机号
  • isPhone(str) - 校验固定电话
  • isPhoneOrTel(str) - 校验手机号或固话

身份信息相关

  • isIdentityCard(str) - 校验身份证号
  • isCreditCard(str) - 校验信用卡号
  • isPassportNumber(str) - 校验护照号

金额相关

  • isAmount(str, maxDecimals) - 通用金额校验
  • isAmountTwoDecimal(str) - 校验金额(最多2位小数)
  • isAmountThreeDecimal(str) - 校验金额(最多3位小数)
  • isPercentage(str, maxDecimals) - 通用百分比校验
  • isDiscount(str) - 校验折扣
  • isTaxRate(str) - 校验税率(使用isPercentage)
  • isPrice(str) - 校验价格

地理位置相关

  • isLatLong(str) - 校验经纬度
  • isLongitude(str) - 校验经度
  • isLatitude(str) - 校验纬度
  • isPostalCode(str) - 校验邮政编码

业务相关

  • isGbCode(str) - 校验20位国标编码
  • isOrderNumber(str) - 校验订单号
  • isTransactionId(str) - 校验交易流水号
  • isBankCard(str) - 校验银行卡号
  • isPayPassword(str) - 校验支付密码
  • isVerificationCode(str) - 校验验证码
  • isProductCode(str) - 校验商品编码
  • isStockQuantity(str) - 校验库存数量

高级校验

  • isJSON(str) - 校验JSON格式
  • isDate(str) - 校验日期格式
  • isISO8601(str) - 校验ISO8601日期格式
  • isTime(str) - 校验时间格式
  • isUUID(str) - 校验UUID格式
  • isHash(str, algorithm) - 校验哈希值
  • isJWT(str) - 校验JWT令牌
  • isMongoId(str) - 校验MongoDB ObjectId
  • isStrongPassword(str) - 校验强密码

开发

# 安装依赖
npm install

# 开发模式(监听文件变化)
npm run dev

# 构建
npm run build

# 测试
npm test

构建产物

  • dist/index.js - UMD格式,适用于浏览器和Node.js
  • dist/index.esm.js - ES Module格式,适用于现代打包工具
  • dist/index.cjs.js - CommonJS格式,适用于Node.js

许可证

MIT