chanceyu / we-validator Goto Github PK
View Code? Open in Web Editor NEW:100: 简单灵活的表单验证插件,支持小程序、浏览器以及Nodejs端使用
License: MIT License
:100: 简单灵活的表单验证插件,支持小程序、浏览器以及Nodejs端使用
License: MIT License
比如选填的邮政编码字段,可以不填,但是如果填写了,必须符合 zip 规则
rules: {
postcode: {
required: false,
zip: true,
},
},
现在有一个格式一样的数组列表需要同时验证,有相应的例子代码吗?
页头引入:
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
请教一下少侠。。
16xxxxx这样的
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
,会提示我字数太少了,请尽量描述清楚
,并且不会提示请输汉字
请问应该怎么解决呢?
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方法 不执行
如题
类似['','']这样的数组校验
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)
checkData(data: object, onMessage?: Function, showMessage?: boolean, fieldMap?: object): void;
checkData的返回值实际是boolean,目前定义中是void,导致实际使用时typescript警告:无法测试 "void" 类型的表达式的真实性
填写完一个必填数据,直接光标定位到下一个必填数据,最后提交的时候会提示下一个数据数据为空,实际已经填写。
中间如果收起过键盘,就没可以通过
苹果真机下面
type Options = {
rules: object,
messages: object,
onMessage?: Function,
multiple?: boolean
}
multiple 应该为 multiCheck?
var isFieldValid = WeValidator.checkValue.call(this, ruleName, value, ruleParam, true);
经过微信小程序开发工具编译的checkData函数调用是发现结果一直为true,原因是上面的代码设置了skip为true导致自定义检验函数不执行
比如:电话号码字段,
既可以是手机号,也可以是座机号。
表单中存在通过循环添加的数组类型数据的表单时怎么校验,有没有一次性校验这种表单的方法
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.