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