validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

支持验证可以为空的字段

Open hulufei opened this issue 11 years ago • 2 comments

有时候某些字段是可以为空的,但是假如不为空的时候也需要验证其值。(验证没有required属性的字段)

比如验证一个可选的手机号:

<input id="mobile" type="text" pattern="^$|^1[3-9]\d{9}$"/>

$('form').validator({ identifie: '[required], #mobile' });

不知道有没有更好的做法?

hulufei avatar Sep 13 '13 07:09 hulufei

ok

hulufei avatar Sep 14 '13 15:09 hulufei

支持验证可以为空的字段,还是蛮有用的。就是有些项可以不填写,但是如果填写了,则必须格式正确。这个特性我已经加上了,供参考 https://github.com/panxuepeng/seajslib/blob/gh-pages/lib/validator/src/validator.js

panxuepeng avatar Dec 30 '13 09:12 panxuepeng