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

kkk-validate

v1.1.2

Published

kkk

Downloads

6

Readme

kkk-validate 验证器

如何使用?

1. npm

    npm install kkk-validate //安装包

    import Rule from 'kkk-validate'
    // ----------- or -------------
    const Rule = requere('kkk-validate') //引入

或下载代码

通过git下载代码, 将kkk-validate.js放入项目目录中

    const Rule = require('./kkk-validate.js') //引入

2. 使用

    //案例1
    // adorn参数是对错误信息的修饰, 可以不填
    // adorn填cancel取消错误信息提示

    // 验证不通过, return掉
    if(Rule.isAllCnChar("kkk", "真实姓名")) return

    //案例2
    console.log(Rule.isMinNumber(9, 10, "金额"))
    //输出 '金额不能小于10
    // 验证不通过, return 掉
    if(Rule.isMinNumber(9, 10, "金额")) return

3. 组合验证

    const password = "123456"
    const rePassword = "123456"
    // 验证密码格式 + 两次输入是否一致
    // 两个验证都通过返回false, 否则返回错误信息
    Rule.group(Rule.isPassword(password, "密码"), Rule.isRepeat(password, rePassword, "密码"), false)
    
    

4. 小程序错误弹窗

    //app.js引入
    import Rule from './utils/kkk-validate'

    //onLaunch里面加上
    Rule.showMessage = function(error) {
      wx.showToast({
        title: error,
        icon: 'none',
        duration: 2000
      })
    }
    

5. vue错误弹窗

    //app.vue引入
    import Rule from 'kkk-validate'

    //beforeMount里面加上
    Rule.showMessage = (error) => {
      this.$message({
        message: error,
        type: "warning",
      });
    }
    

函数

1. 数字方法

| 名称 | 功能 | ---- | ---- | isNumber (number, n_flag, adorn) | 验证数字 | isMinNumber (number, min_number, n_flag, adorn) | 验证数值最小范围 | isMaxNumber (number, max_number, n_flag, adorn) | 验证数值最大范围 | isMinMaxNumber (number, min_number, max_number, n_flag, adorn) | 验证数值范围 | isNumberSL (number, max_length, adorn) | 验证x位小数

参数

| 名称 | 必填 | 默认值 | 类型 | 参数说明 | --- | --- | --- | --- | --- | number | 是 | | string\number | 被验证值 | n_flag | 否 | true | boolean | 为true验证包含小数false只能验证整数,小数报错 | adorn | 否 | | string | 错误提示修饰 | min_number | 是 | | number | 最小数值范围 | max_number | 是 | | number | 最大数值范围

2. 字符串方法

| 名称 | 功能 | ---- | ---- | isMinLength (string, min_length, adorn) | 验证字符串最小长度 | isMaxLength (string, max_length, adorn) | 验证字符串最大长度 | isLength (string, min_length, max_length, adorn) | 验证字符串长度 | isNull (string, adorn)| 验证空字符串 | isSpace (string, adorn) | 验证包含空格 | isNoCnChar (string, adorn) | 验证包含汉字 | isAllCnChar (string, adorn) | 验证全为汉字 | isEnNumUline (string, adorn) | 验证英文 数字 下划线

参数

| 名称 | 必填 | 默认值 | 类型 | 参数说明 | --- | --- | --- | --- | --- | string | 是 | | string\number | 被验证值 | adorn | 否 | | string | 错误提示修饰 | min_length | 是 | | number | 最小长度 | max_length | 是 | | number | 最大长度

3. 格式验证

| 名称 | 功能 | ---- | ---- | isEmail (string) | 验证邮箱格式 | isUrl (string) | 验证url格式 | isPhone (string) | 验证手机号格式 | isIdCard (string) | 验证身份证格式

参数

| 名称 | 必填 | 默认值 | 类型 | 参数说明 | --- | --- | --- | --- | --- | string | 是 | | string\number | 被验证值

4. 其他验证

| 名称 | 功能 | ---- | ---- | isPassword (data, p_min, p_max, adorn) | 验证密码格式 | isRepeat (data, re_data, adorn) | 重复验证 | group (fn, ... , arr_flag) | 组合验证

参数

| 名称 | 必填 | 默认值 | 类型 | 参数说明 | --- | --- | --- | --- | --- | data | 是 | | string\number | 被验证值 | adorn | 否 | | string | 错误提示修饰 | p_min | 否 | 6 | number | 最小长度 | p_max | 否 | 16 | number | 最大长度 | fn | 是 | | function | 验证函数 | arr_flag | 否 | true | boolean | 为true验证不通过,停止后面的验证false遇到错误继续验证,以数组形式返回错误信息