forked from guillaumepotier/Parsley.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsley.extend.js
53 lines (43 loc) · 1.67 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
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());
}
}
, 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."
}
});
}(window.jQuery || window.Zepto));