Tring Allow to both Integer
as well as Decimal
as input. And restricting on total length which should not be greater that 11(MaximumLength of input including decimal point)
eg. Allowed values are
1.0, 1.123546, 12345678912,12.12345678,...etc.
i.e. If value contain Decimal
point then allow at least one digit
after Decimal
point otherwise allow complete integer number with maximum length i.e. 11
I have declared regular expression as:
/^-?(([0-9]{0,11}) | ([0-9]{0,9}.[0-9]{1,2}))$/
And the values I'm testing against as: 6666666.666
But the result always not getting matched.
NOTE: If length of digit before decimal point is 7 then allow 3 digit after decimal point in case Maximum allowed length is 11.
Fractional
part length decided based on integral
part.
------------------------ JQuery Function-----------------------------------
function Validate(sender, precision)
{
var variable;
if (precision != "0")
{
var valueLength = sender.value.indexOf('.');
if (sender.id.indexOf("Longitude") > -1)
variable = "-?[0-9,]{0," + parseInt($(sender).attr("data-length") - (parseInt(precision) + 1)) + "}[.][0-9]{0," + parseInt(precision) + "}$";
else
variable = "-?(([0-9]{0," + parseInt($(sender).attr("data-length")) + "})|([0-9]{0," + parseInt($(sender).attr("data-length") - 2) + "}.[0-9]{1," + parseInt
($(sender).attr("data-length") - (valueLength + 2)) + "}))$";
}
else
variable = "-?[0-9,]{0," + parseInt($(sender).attr("data-length")) + "}$";
var re = new RegExp('^' + variable);
if (sender.value != "")
{
if (!re.test(sender.value))
{
alert('Not Matched');
}
else
{
alert('Matched');
}
}
}