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-by-health

v1.1.9

Published

BY-HEALTH data validation

Downloads

34

Readme

Install

    npm i validate-by-health

Validate Usage

    ...
    import validate from 'validate-by-health';
    ...
    export class example extends React.Component {
        ...
        handleSubmit = () => {
            const error = validate({
				VPhone: ['11845674324', '请输入正确手机号码', 'strict'], // return 请输入正确手机号码
				VName: 'asd@#', // return 姓名请使用非特殊字符
				VEnglish: ['jk123123', '请使用英文名'], // return 请使用英文名
				VSecurityCode: '1asd21as1' // return 请输入16位防伪码
			});

            if (error) {
                this.showModal(error); // 显示错误
                return;
            }

            this.showLoading();
            
            fetch(Api).then( ...
        }
        ...
        render(){
            return <button onClick={this.handleSubmit}>提交</button>;
        }
    }
    export default example;

validate(data, Boolean) 验证方法

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证数据,{key: value} key是验证器,value是验证数据和验证规则参数 | Object | 必填 | | Boolean | 控制返回结果,设为true时完成整个data的验证以{key: returns}形式返回, | Boolean | 默认false |

  • 注意:多个数据用到同类型验证器时请使用key_(lable)
    const error = validate({
        'VPhone_Jhon': '13111111111',
        'VPhone_Lucy': '13875745147',
        'VPhone_Lee': '13',
        ...
    }, true);

返回结果

    return error = {
        VPhone_Jhon: false,
        VPhone_Lucy: false,
        VPhone_Lee: '请输入正确手机号码'
    }

Validate 键值属性(String or Array)

  • VPhone(data, Msg, strict)
	validate({VPhone: [data, Msg, strict]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证电话号码 | string | 必填 | | Msg | 错误返回信息 | string | 不填时显示默认提示信息 | | strict | 开启严格模式 | string | 设为'strict'时开启严格验证,不填时只验证已1开头的11位手机号码 |

  • VName(data, Msg, Zh)
	validate({VName: [data, Msg, Zh]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证名字 | string | 必填 | | Msg | 错误返回信息 | string | 不填时显示默认提示信息 | | Zh | 开启严格模式 | string | 设为'Zh'时开启严格验证,只能填写2以上中文字符 |

  • VEmail(data, Msg)
	validate({VEmail: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证email | string | 必填 | | Msg | 错误返回信息 | string | 不填时显示默认提示信息 |

  • VIdCard(data, Msg)
	validate({VIdCard: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证身份证合法性 | string | 必填 | | Msg | 错误返回信息 | string | 不填时显示默认提示信息 |

  • VSecurityCode(data, Msg)
	validate({VSecurityCode: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证防伪码 | string | 必填 | | Msg | 错误返回信息 | string | 不填时显示默认提示信息 |

  • VBarCode(data, Msg)
	validate({VBarCode: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证条形码 | string | 必填 | | Msg | 错误返回信息 | string | 不填时显示默认提示信息 |

  • VVerificationCode(data, Msg, length)
	validate({VVerificationCode: [data, Msg, length]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证名字 | string | 必填 | | Msg | 错误返回信息 | string | 不填时显示默认提示信息 | | length | 开启严格模式 | number | 验证码的长度(number)不填时默认验证4位验证码 |

  • VRequire(data, Msg, length)
	validate({VRequire: [data, Msg, length]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证最少字符数 | string | 必填 | | Msg | 错误返回信息 | string | 必填 | | length | 开启严格模式 | number | 最少要求多少位字符(number)不填时默认1个字符 |

  • VLimit(data, Msg, length)
	validate({VLimit: [data, Msg, length]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证最大字符数 | string | 必填 | | Msg | 错误返回信息 | string | 必填 | | length | 开启严格模式 | number | length: 最多输入多少位字符(number)不填时默认20个字符 |

  • VNumber(data, Msg)
	validate({VNumber: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证数字 | string | 必填 | | Msg | 错误返回信息 | string | 必填 |

  • VChinese(data, Msg)
	validate({VChinese: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ | data | 验证中文 | string | 必填 | | Msg | 错误返回信息 | string | 必填 |

  • VEnglish(data, Msg)
	validate({VEnglish: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ data | 验证英文 | string | 必填
Msg | 错误返回信息 | string | 必填

  • VEqual(dataA, dataB, Msg, turnOver)

验证是否相等

	validate({VEqual: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ dataA | 比较值A | string | 必填
dataB | 比较值B | string | 必填
Msg | 错误返回信息 | string | 非必填
turnOver | false时验证相等,true时验证不相等 | Boolean | false

  • VdangerousChar(data, Msg)
	validate({VDangerousChar: [data, Msg]})

属性 | 说明 | 类型 | 默认值 -----|-----|-----|------ data | 危险性字符验证,防止脚本或SQL注入 | string | 必填
Msg | 错误返回信息 | string | 必填