admin管理员组文章数量:1325236
Is it possible to use the date validation in Parsley v2.X as in the previous version?
Example (v1.x): parsley-onorafterdate="#currentDate"
I cannot find information in the documention about this issue.
Is it possible to use the date validation in Parsley v2.X as in the previous version?
Example (v1.x): parsley-onorafterdate="#currentDate"
I cannot find information in the documention about this issue.
Share Improve this question edited Apr 10, 2014 at 2:42 dvdgsng 1,74116 silver badges27 bronze badges asked Apr 9, 2014 at 17:37 er_benjier_benji 3054 silver badges9 bronze badges1 Answer
Reset to default 7I believe for any validators outside of the documented core validators you will need to either copy a pre-built validator or make your own.
To add additional validators you will simply need to add the validator to a window config variable before you include parsley.
They have an example here: http://parsleyjs/doc/examples/customvalidator.html
If you are using requirejs I believe you would be able to create a new module and then simply require your additional validators in the requirejs define method although I haven't tested that theory yet!
As an example:
First I define my custom parsley dom attribute
<input name="date" type="text" data-parsley-trigger="change" data-parsley-date required/>
In my script before parsley is loaded:
window.ParsleyConfig = window.ParsleyConfig || {};
window.ParsleyConfig.validators = window.ParsleyConfig.validators || {};
window.ParsleyConfig.validators.date = {
fn: function (value) {
return /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/.test(value);
},
priority: 256
};
The ParsleyConfig.validators.date matches my custom dom attribute (date) and the function returns true or false based on a regex.
In theory if you have the logic for the old parsley validation method you want to use you can just paste that inside your custom validator, but hopefully it should look pretty easy to build you own!
本文标签: javascriptParsleyjs date validation in v2xStack Overflow
版权声明:本文标题:javascript - Parsley.js date validation in v2.x - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742169327a2426422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论