forked from guillaumepotier/Parsley.js
/
parsley.extend.js
63 lines (51 loc) · 2.01 KB
/
parsley.extend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
window.ParsleyConfig = window.ParsleyConfig || {};
(function ($) {
window.ParsleyConfig = $.extend( true, {}, window.ParsleyConfig, {
validators: {
minwords: function ( val, nbWords ) {
val = val.replace( /(^\s*)|(\s*$)/gi, "" );
val = val.replace( /[ ]{2,}/gi, " " );
val = val.replace( /\n /, "\n" );
val = val.split(' ').length;
return val >= nbWords;
}
, maxwords : function ( val, nbWords ) {
val = val.replace( /(^\s*)|(\s*$)/gi, "" );
val = val.replace( /[ ]{2,}/gi, " " );
val = val.replace( /\n /, "\n" );
val = val.split(' ').length;
return val <= nbWords;
}
, rangewords: function ( val, obj ) {
val = val.replace( /(^\s*)|(\s*$)/gi, "" );
val = val.replace( /[ ]{2,}/gi, " " );
val = val.replace( /\n /, "\n" );
val = val.split(' ').length;
return val >= obj[0] && val <= obj[1];
}
, greaterthan: function ( val, elem, self ) {
self.options.validateIfUnchanged = true;
return new Number(val) > new Number($( elem ).val());
}
, lessthan: function ( val, elem, self ) {
self.options.validateIfUnchanged = true;
return new Number(val) < new Number($( elem ).val());
}
, beforedate: function ( val, elem, self) {
return Date.parse(val) < Date.parse($(elem).val());
}
, afterdate: function ( val, elem, self) {
return Date.parse($(elem).val()) < Date.parse(val);
}
}
, messages: {
minwords: "This value should have %s words at least."
, maxwords: "This value should have %s words maximum."
, rangewords: "This value should have between %s and %s words."
, greaterthan: "This value should be greater than %s."
, lessthan: "This value should be less than %s."
, beforedate: "This date should be before %s."
, afterdate: "This date should be after %s."
}
});
}(window.jQuery || window.Zepto));