GithubHelp home page GithubHelp logo

chanceyu / we-validator Goto Github PK

View Code? Open in Web Editor NEW
236.0 236.0 53.0 214 KB

:100: 简单灵活的表单验证插件,支持小程序、浏览器以及Nodejs端使用

License: MIT License

JavaScript 83.15% HTML 11.29% Vue 3.24% EJS 2.31%
miniprogram node-validator validation validator weapp wechat wechat-mini-program

we-validator's Introduction

𝐇𝐞𝐥𝐥𝐨 𝐭𝐡𝐞𝐫𝐞, 𝐟𝐞𝐥𝐥𝐨𝐰 <𝚌𝚘𝚍𝚎𝚛𝚜/>!

we-validator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

we-validator's Issues

请问支持选填字段吗?

比如选填的邮政编码字段,可以不填,但是如果填写了,必须符合 zip 规则

rules: {
    postcode: {
        required: false,
        zip: true,
    },
},

如何验证数组?

现在有一个格式一样的数组列表需要同时验证,有相应的例子代码吗?

Cannot read property 'checkData' of undefined。

页头引入:
const WeValidator = require('../../utils/we-validator')

page中添加:

initValidator() {
this.oValidator = new WeValidator({
rules: {
username: {
required: true
},
phoneno: {
required: true,
mobile: true
},
str: {
required: true,
stringLength: 3
},
},
messages: {
username: {
required: '请输入用户名'
},
phoneno: {
required: '请输入手机号',
mobile: '手机号格式不正确'
},
str: {
required: '请输入字符串',
stringLength: '字符串长度不对'
},
},
})
},

form函数中:

let { value } = e.detail

console.log(value)
if (!this.oValidator.checkData(value)) return

// 开始提交表单
// wx.request
console.log('submiting')

点击button就报错:

thirdScriptError
Cannot read property 'checkData' of undefined;at pages/mycard/addcard page submitCard function
TypeError: Cannot read property 'checkData' of undefined

请教一下少侠。。

maxChinese和chinese校验错误

  initValidator() {
    var _this = this;
    this.validatorInstance = new WeValidator({
      multiCheck: true,
      onMessage: function (data) {
        _this.setData({
          error_title: data.title.msg,
        })
      },
      rules: {
        title: {
          required: true,
          chinese: true,
          minChinese: 5,
          maxChinese: 18
        }
      },
      messages: {
        title: {
          required: '您得描述一下你的信息内容',
          chinese:'请输汉字',
          minChinese: '字数太少了,请尽量描述清楚',
          maxChinese: '字数太多了',
        }
      },
    })
  },

我在title里输入任何数字,比如11,会提示我字数太少了,请尽量描述清楚,并且不会提示请输汉字

请问应该怎么解决呢?

添加自定义规则后,checkData时不生效

const WeValidator = require('we-validator')

// 添加自定义规则(这两种写法一样)
WeValidator.addRule('theRuleName', {
message: '默认错误提示文字',
rule(value, param){
return /\d/.test(value)
}
})

// 使用方式一,实例化
this.validatorInstance = new WeValidator({
rules: {
field1: {
theRuleName: true
}
},
messages: {
field1: {
theRuleName: '提示信息'
}
}
})

执行 this.validatorInstance.checkData(params) 是, 自定义规则中的rule方法 不执行

Trying to get in touch regarding a security issue

Hey there!

I'd like to report a security issue but cannot find contact instructions on your repository.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

TypeScript的定义问题

checkData(data: object, onMessage?: Function, showMessage?: boolean, fieldMap?: object): void;

checkData的返回值实际是boolean,目前定义中是void,导致实际使用时typescript警告:无法测试 "void" 类型的表达式的真实性

必填都已经填写,但是会提示未填写

填写完一个必填数据,直接光标定位到下一个必填数据,最后提交的时候会提示下一个数据数据为空,实际已经填写。

中间如果收起过键盘,就没可以通过

苹果真机下面

multiple类型声明错误

type Options = {
rules: object,
messages: object,
onMessage?: Function,
multiple?: boolean
}

multiple 应该为 multiCheck?

BUG: checkData()函数 skip参数一直为ture

var isFieldValid = WeValidator.checkValue.call(this, ruleName, value, ruleParam, true);
经过微信小程序开发工具编译的checkData函数调用是发现结果一直为true,原因是上面的代码设置了skip为true导致自定义检验函数不执行

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.