一个类似laravel的js验证模块, 支持Nodejs与浏览器环境.
npm:https://www.npmjs.com/package/validator
npm:npm i validator前端的验证工具,无其他包依赖无样式,可以适合任何环境,可根据项目环境自行组装提示信息反馈给用户。
兼容IE6以上版及目前流行的浏览器。
for example
class AddContentValidator extends LinValidator{
constructor(){
super()
this.image= [
new Rule('isNotEmpty', '内容封面不能为空'),
]
this.type = [
new Rule('isNotEmpty', '内容类型不能为空'),
new Rule('isInt', '内容id的类型必需是数字'),
]
this.title = [
new Rule('isNotEmpty','内容标题不能为空'),
]
this.content = [
new Rule('isNotEmpty','内容介绍不能为空'),
]
this.url = [
new Rule('isOptional'),
new Rule('isURL', '内容外链必须是合法的url地址'),
]
this.pubdate = [
new Rule( 'isNotEmpty', '发布不能为空'),
new Rule('isISO8601','发布日期格式不正确'),
]
this.status = [
new Rule( 'isNotEmpty', '内容有效状态未指定'),
new Rule('isInt', '内容有效状态标识不正确'),
]
}
}
export {AddContentValidator}