-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
支持验证可以为空的字段 #32
base: master
Are you sure you want to change the base?
支持验证可以为空的字段 #32
Conversation
@@ -246,7 +246,8 @@ | |||
// 但通过来说我们更需要的是 checked 的状态 | |||
// 暂时去掉 radio/checkbox/linkage/aorb 的 notEmpty 检测 | |||
if(!(/^(?:radio|checkbox)$/.test(type) || aorb) && !patterns['text'](val)) | |||
return validateReturn.call(this, $item, klass, parent, 'empty') | |||
return validateReturn.call(this, $item, klass, parent, | |||
$item.is('[required]') ? 'empty' : ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
意思是非 [required]
就不显示 empty
这个 class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也可以这么说,我想的是可以验证非[required]
的字段,为空的时候认为是合法的,但是不为空的时候就需要验证。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个目前不太好加进去,建议你先在自己的项目里面改
ok |
支持验证可以为空的字段,还是蛮有用的。就是有些项可以不填写,但是如果填写了,则必须格式正确。这个特性我已经加上了,供参考 https://github.com/panxuepeng/seajslib/blob/gh-pages/lib/validator/src/validator.js |
有时候某些字段是可以为空的,但是假如不为空的时候也需要验证其值。(验证没有required属性的字段)
比如验证一个可选的手机号:
不知道有没有更好的做法?