Reputation: 31
It's surely a simple question for somebody.
I found this pattern for jquery:
/^([0-9]{0,12})$/,/^[0-9]{1,12}[\,]{1}(|[0-9]{0,4})$/
The
/^([0-9]{0,12})$/
and
/^[0-9]{1,12}[\,]{1}(|[0-9]{0,4})$/
I don't understand the pattern.
My only question is and I find nothing via google: What does the comma make?
Is he checking two patterns or does this comma do something special?
Here is the link http://freedns.remdex.info/JQuery-simple-input-validation-plugin-74a.html
So when he accepts arrays it means that he checks whether if one it is true?
Upvotes: 3
Views: 2872
Reputation: 39542
Now that you stated your actual source we can come to the conclusion that the full line is:
$("#only_int_float").rval([/^([0-9]{0,6})$/,/^[0-9]{1,6}[\.|,]{1}(|[0-9]{0,2})$/]);
As you may notice, there's [
and ]
brackets, which means this is an array. So basically, it would be the same as the following:
var regexes = new Array(
/^([0-9]{0,6})$/,
/^[0-9]{1,6}[\.|,]{1}(|[0-9]{0,2})$/
);
$("#only_int_float").rval(regexes);
In the same source, you can find the code:
$.each(
regularExpression,
function( intIndex, objValue ){
var re = new RegExp(objValue);
if((re.exec(instance.value) || instance.value == '') && allOk == false)
{
allOk = true;
}
}
);
Which means "for each regex in the variable regularExpression
, run the following function (where it checks if the regex matches).
allOk
clearly gets set to true if there's just one match, so you can use this array as an OR
statement (if regex #1 doesn't match, check regex2 etc.).
Upvotes: 3
Reputation: 17576
if this is for PHP
preg_replace accepts arrays as arguments
this
$str = preg_replace('/[\\r\\n!.,\'“”;’?-\s+]/', ' ', $str);
$str=preg_replace('/\s+\S{1,2}(?!\S)|(?<!\S)\S{1,2}\s+/', '', $str);
is equalnt to
str = preg_replace(array('/^([0-9]{0,12})$/','/^[0-9]{1,12}[\,]{1}(|[0-9]{0,4})$/'), array(' ', ''), $str);
Upvotes: 0