Open
Conversation
Owner
There was a problem hiding this comment.
意思是非 [required] 就不显示 empty 这个 class?
Author
There was a problem hiding this comment.
也可以这么说,我想的是可以验证非[required]的字段,为空的时候认为是合法的,但是不为空的时候就需要验证。
Author
|
ok |
|
支持验证可以为空的字段,还是蛮有用的。就是有些项可以不填写,但是如果填写了,则必须格式正确。这个特性我已经加上了,供参考 https://github.com/panxuepeng/seajslib/blob/gh-pages/lib/validator/src/validator.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
有时候某些字段是可以为空的,但是假如不为空的时候也需要验证其值。(验证没有required属性的字段)
比如验证一个可选的手机号:
不知道有没有更好的做法?