Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript question - validating dollar amount

Javascript question - validating dollar amount

Scheduled Pinned Locked Moved Web Development
questionjavascriptregex
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    john_paul
    wrote on last edited by
    #1

    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") } }

    C 1 Reply Last reply
    0
    • J john_paul

      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") } }

      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      Check out the script here[^]. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

      J 1 Reply Last reply
      0
      • C Curtis Schlak

        Check out the script here[^]. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

        J Offline
        J Offline
        john_paul
        wrote on last edited by
        #3

        Thanks for the reply, but can't view it. Javascriptkit.com's server has been down for two days

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups