Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation

Status
Not open for further replies.

siuk

Programmer
Aug 23, 2001
38
GB
Hi, I was wondering if anyone could help me out?

I want to be able to validate a user given value. This value is a cash value.

I want the user to be able to input for example $5 in 2 different ways -

1 - 5
2 - 5.00

Does anyone have a piece of code or a link to help me?

Many Thanks

Simon
 
You could just split the input value at the ".", and take the first part of the returned array as the dollar amount

example of use given:

<script language=javascript>
var amount=&quot;5.00&quot;
splits=amount.split(&quot;.&quot;)
var dollars=splits[0]
document.write(dollars)
</script>

Ian

 
Or use someting like:
Code:
function checkAmount( element ) {
    var amount = element.value;
    if( amount.match( /\d+(\.\d{2})?/ ) ) {
        return true;
    } else {
        return false;
    }
}
I can't check this at the moment, but I think it should work. Cheers, Neil s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top