How to make the last two numbers typed into a asp:textbox decimals?

Hello Experts,

I have an asp:textbox with the following regular expression validator:

<asp:RegularExpressionValidator ID="rev_case_exp_cost_txt" runat="server" ControlToValidate="case_exp_cost_txt" Type="Integer" Operator="DataTypeCheck" ErrorMessage="Invalid Format" ValidationExpression="^\d{1,11}(?:\.\d\d)?$"></asp:RegularExpressionValidator>

Open in new window


How can I get it to automatically make the last two numbers entered as the decimals?  For example, if the user types 300, it should show 3.00 after they tab out of the field - or 50000 would be 500.00.  

I am using asp.net and c#.

Any help would be greatly appreciated.

Thanks,
J
ferguson_jeraldAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Majority of the script taken from here:
http://bytes.com/topic/javascript/answers/556779-add-decimal-number

Splice function found online found online


add this to your textbox:

 onBlur="checkDecimal(this,this.value)

<script type="text/javascript">
function checkDecimal(obj, objStr){
    var objNumber;
    if(isNaN(objStr) && objStr!=''){
        alert('Value entered is not numeric');
        objNumber = '0.00';
    }
    else if(objStr==''){
        objNumber = '0.00';
    }
    else if(objStr.indexOf('.')!=-1){
        if(((objStr.length) - (objStr.indexOf('.')))>3){
            objStr = objStr.substr(0,((objStr.indexOf('.'))+3));
        }
        if(objStr.indexOf('.')==0){
            objStr = '0' + objStr;
        }
        var sLen = objStr.length;
        var TChar = objStr.substr(sLen-3,3);
        if(TChar.indexOf('.')==0){
            objNumber = objStr;
        }
        else if(TChar.indexOf('.')==1){
            objNumber = objStr + '0';
        }
        else if(TChar.indexOf('.')==2){
            objNumber = objStr + '00';
        }
    }
    else{
        objNumber = objStr.splice(len(objstr)-2,0,'.');
    }
    obj.value = objNumber;
}

String.prototype.splice = function( idx, rem, s ) {
    return (this.slice(0,idx) + s + this.slice(idx + Math.abs(rem)));
};
</script>

Open in new window

0
Manoj PatilSr. Software EngineerCommented:
Hi you can try JQuery for this.
Check this link
http://www.texotela.co.uk/code/jquery/numeric/
And Sample Code for this is attached below.
HTML CODE
SampleCode.html

JAVASCRIPT FILES
jquery.numeric.js

jquery.numeric.min.js
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ferguson_jeraldAuthor Commented:
I tested both suggestions and they both worked!  Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.