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

check-string

v3.0.16

Published

[![NPM version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][npm-url] [![Build Status](https://travis-ci.org/heifade/check-string.svg?branch=master)](https://travis-ci.org/heifade/check-string) [![Coverage Status](https://coveralls.io/repos/gi

Downloads

68

Readme

check-string

NPM version NPM Downloads Build Status Coverage Status

源代码及文档

源代码 开发文档

安装

npm install check-string

介绍

check-string的主要功能:

  • 检查字符串是否符合要求,如整型,浮点型,实数,邮件,手机号码,座机号码,身份证号码等。
  • 检查字符串输入长度是否符合要求
  • 检查字符串输入值是否符合最大值,最小值要求 check-string的主要特点:
  • 1.整型检查:是否是整型格式,是否可以为空,是否在最大最小值范围内。
  • 2.浮点型检查:是否是浮点数格式,是否可以为空,是否在最大最小值范围内,小数位数。
  • 3.实数型检查:是否是实数格式,是否可以为空,是否在最大最小值范围内,小数位数。
  • 4.邮件检查:是否是邮件格式
  • 5.手机号码检查:是否是手机号码格式
  • 6.座机号码检查:是否是座机号码格式
  • 7.身份证号码检查:是否是身份证号码格式

方法总览

isInteger 整型检查 isFloat 浮点型检查 isReal 实数型检查 isEmail 邮件检查 isPhoneNumber 手机号码检查 isFixedTelephoneNumber 座机号码检查 isIDCardNo 身份证号码检查

例子

例子1 整型检查

import { isInteger } from "check-string";
...
let str = "123"
let result = isInteger(str, { canNull: true, min: 10, max: 10000 }); //str可以为null,最大10000,最小10
if(!result.success) {
  console.log(result.error.code); // 输出错误编号
  console.log(result.error.cn); // 输出错中文错误
  console.log(result.error.en); // 输出错英文错误
}

例子2 浮点型检查

import { isFloat } from "check-string";
...
let str = '12.53';
let result = isFloat(str, { canNull: true, max: 500, min: 0, decimals: 2 }); //str可以为null,最大500,最小0, 小数点后最多2位小数
if (!result.success) {
  console.log(result.error.code); // 输出错误编号
  console.log(result.error.cn); // 输出错中文错误
  console.log(result.error.en); // 输出错英文错误
}

例子3 实数型检查

import { isReal } from "check-string";
...
let str = "23.56"
let result = isReal(str, { canNull: true, max: 500, min: 0, decimals: 2 }); //str可以为null,最大500,最小0,小数点后最多2位小数
if(!result.success) {
  console.log(result.error.code); // 输出错误编号
  console.log(result.error.cn); // 输出错中文错误
  console.log(result.error.en); // 输出错英文错误
}

例子4 邮件检查

import { isEmail } from "check-string";
...
let str = '[email protected]';
let result = isEmail(str, { canNull: true }); //str可以为null
if (!result.success) {
  console.log(result.error.code); // 输出错误编号
  console.log(result.error.cn); // 输出错中文错误
  console.log(result.error.en); // 输出错英文错误
}

例子5 手机号码检查

import { isPhoneNumber } from "check-string";
...
let str = "15811111111"
let result = isPhoneNumber(str, { canNull: true }); //str可以为null
if(!result.success) {
  console.log(result.error.code); // 输出错误编号
  console.log(result.error.cn); // 输出错中文错误
  console.log(result.error.en); // 输出错英文错误
}

例子6 座机号码检查

import { isFixedTelephoneNumber } from "check-string";
...
let str = "010-22345678"
let result = isFixedTelephoneNumber(str, { canNull: true }); //str可以为null
if(!result.success) {
  console.log(result.error.code); // 输出错误编号
  console.log(result.error.cn); // 输出错中文错误
  console.log(result.error.en); // 输出错英文错误
}

例子7 身份证号码检查

import { isIDCardNo } from "check-string";
...
let str = "330683180001017218"
let result = isIDCardNo(str, { canNull: true }); //str可以为null
if(!result.success) {
  console.log(result.error.code); // 输出错误编号
  console.log(result.error.cn); // 输出错中文错误
  console.log(result.error.en); // 输出错英文错误
}