Javascript question - validating dollar amount
-
I am trying to validate a text box as the user keys in the dollar amount. Using the below function, if the user keys in "a", it does the alert If I key in 10aa, I get the alert but if I key in 10a, I don't get the alert. Any ideas about what I am doing wrong. Thanks John function TestForNumber( obj, event ) { var curChar = String.fromCharCode( event.keyCode ); var inpStr = obj.value + curChar; result = inpStr.match( '^[0-9]+\.?[0-9]??[0-9]?$' ); if ( ! result ) { event.returnValue = false; event.cancel = true; alert("Unapplied cash can only be numerical data") } }
-
I am trying to validate a text box as the user keys in the dollar amount. Using the below function, if the user keys in "a", it does the alert If I key in 10aa, I get the alert but if I key in 10a, I don't get the alert. Any ideas about what I am doing wrong. Thanks John function TestForNumber( obj, event ) { var curChar = String.fromCharCode( event.keyCode ); var inpStr = obj.value + curChar; result = inpStr.match( '^[0-9]+\.?[0-9]??[0-9]?$' ); if ( ! result ) { event.returnValue = false; event.cancel = true; alert("Unapplied cash can only be numerical data") } }
-
Thanks for the reply, but can't view it. Javascriptkit.com's server has been down for two days