Skip to content

enhance split function using regex as delim #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions form-validator/jquery.form-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @website http://formvalidator.net/
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.2.beta.13
* @version 2.2.beta.14
*/
(function($) {

Expand Down Expand Up @@ -468,32 +468,34 @@

/**
* A bit smarter split function
* delimiter can be space comma dash or pipe
* @param {String} val
* @param {Function|String} [func]
* @param {String} [delim]
* @returns {Array|void}
*/
$.split = function(val, func, delim) {
$.split = function(val, func) {
if( typeof func != 'function' ) {
// return string
// return array
if( !val )
return [];
var values = [];
$.each(val.split(func ? func:','), function(i,str) {
str = $.trim(str);
if( str.length )
values.push(str);
});
$.each(val.split(func ? func: /[,|-\s]\s*/g ),
function(i,str) {
str = $.trim(str);
if( str.length )
values.push(str);
}
);
return values;
} else if( val ) {
// use callback on each
if( !delim )
delim = ',';
$.each(val.split(delim), function(i, str) {
str = $.trim(str);
if( str.length )
return func(str, i);
});
// exec callback func on each
$.each(val.split(/[,|-\s]\s*/g),
function(i, str) {
str = $.trim(str);
if( str.length )
return func(str, i);
}
);
}
};

Expand Down Expand Up @@ -884,7 +886,7 @@
throw new Error('Using undefined validator "'+rule+'"');
}

}, ' ');
});

if( typeof validationErrorMsg == 'string' ) {
$elem.trigger('validation', false);
Expand Down Expand Up @@ -1019,7 +1021,7 @@
numericRangeCheck : function(value, rangeAllowed)
{
// split by dash
var range = $.split(rangeAllowed, '-');
var range = $.split(rangeAllowed);
// min or max
var minmax = parseInt(rangeAllowed.substr(3),10)
// range ?
Expand Down