How to validate both integer and decimal values using regular expression?
<p>Tring Allow to both <code>Integer</code> as well as <code>Decimal</code> 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 <code>Decimal</code> point then allow at least one <code>digit</code> after <code>Decimal</code> point otherwise allow complete integer number with maximum length i.e. 11</p>

<p>I have declared regular expression as:
<code>/^-?(([0-9]{0,11}) | ([0-9]{0,9}.[0-9]{1,2}))$/</code></p>

<p>And the values I'm testing against as: 6666666.666</p>

<p>But the result always not getting matched.</p>

<p>NOTE: If length of digit before decimal point is 7 then allow 3 digit after decimal point in case Maximum allowed length is 11.
      <code>Fractional</code> part length decided based on <code>integral</code> part.</p>

<p>------------------------ JQuery Function-----------------------------------</p>

<pre><code>function Validate(sender, precision)
{
    var variable;
    if (precision != "0") 
    {
        var valueLength = sender.value.indexOf('.');
        if (sender.id.indexOf("Longitude") &gt; -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');
        }
    }
</code></pre>

<p>}</p>