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 🙏

© 2024 – Pkg Stats / Ryan Hefner

validate-methods

v1.1.0

Published

常用验证函数

Downloads

114

Readme

validate-methods

这是一个常用的验证函数库, 收集了日期, 邮件, 网址, 银行卡, 身份证等验证函数...

Install And Usega

Using Browser:

<script src="./dist/index.lib.js"></script>
<script>
    console.log(ValidateMethods.IsEmail("[email protected]") === true);
</script>

Or Using npm:

npm install --save validate-methods
import { IsEmail } from "validate-methods";
console.log(IsEmail("[email protected]") === true);

Methods

通用验证

  • Required(value: any) 验证值是否必填
  • MinLength(str: string, min: number, equal: boolean = true) 验证字符串长度是否小于 min
  • MaxLength(str: string, max: number, equal: boolean = true) 验证字符串长度是否大于 max
  • RangeLength(str: string, min: number, max: number, equal: boolean = true) 验证字符串长度在范围内
  • EqualLength(str: string, length: number) 验证字符串长度是否等于 length
  • Min(val: number | string, min: number, equal: boolean = true) 验证数值是否小于 min
  • Max(val: number | string, max: number, equal: boolean = true) 验证数值是否大于 min
  • Range(val: number | string, min: number, max: number, equal: boolean = true) 验证数值是否在某个范围内
  • Pattern(val: string, regexp: string | RegExp) 验证字符串是否匹配正则

类型验证

  • IsNumber(number: string | number) 验证数值类型
  • IsFunction(func: Function) 验证函数类型
  • IsArray(array: any[]) 验证数组类型

格式验证

  • IsEmail(email: string) 验证邮箱格式
  • IsUrl(url: string) 验证网址格式
  • AcceptSuffix(val: string, suffixs: string[]) 验证合法后缀
  • ZipCode(val: string) 验证邮政编码格式
  • PhoneNo(val: string) 验证手机号格式
  • Tel(val: string) 验证座机号码格式
  • Chinese(val: string) 验证是否中文字符
  • NotChinese(val: string) 验证是否不包含中文字符
  • BankCard(card: string) 验证银行卡号格式
  • IdCardNo(cardNo: string) 验证身份证格式

日期验证

  • IsTime(time: string) 验证时间字符串格式, 如: 10:32:33
  • IsDateFormat(date: string) 验证日期字符串格式, 如: 2018-03-26
  • IsDateISO(date: string) 验证日期字符串格式, 如: 2018-03-26 10:32:33

数值验证

  • IsDigits(number: number | string) 验证整数格式
  • IsStep(val: number | string, step: number) 验证数值是否为指定倍数
  • Amount(amount: string | number, canBeZero: boolean = false, bits: number = 6) 验证金额格式