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. javascirpt validation

javascirpt validation

Scheduled Pinned Locked Moved Web Development
questionjavascriptregextutorial
2 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.
  • G Offline
    G Offline
    Goodway
    wrote on last edited by
    #1

    Dear all, i need to do a javascript validation for a textbox, this textbox is for the amount, the user can enter for example the value: 2 or 3.2 or 0.7 I should allow him to enter a digit and also ".", what is the simplest regular expression to do this. The developer that worked previously on this project, put this regular expression: var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; I can't understand it specially the -? in the begining of each part, what exactly do the "-?" and also for which validation this regular expression is used. Thanks.

    W 1 Reply Last reply
    0
    • G Goodway

      Dear all, i need to do a javascript validation for a textbox, this textbox is for the amount, the user can enter for example the value: 2 or 3.2 or 0.7 I should allow him to enter a digit and also ".", what is the simplest regular expression to do this. The developer that worked previously on this project, put this regular expression: var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; I can't understand it specially the -? in the begining of each part, what exactly do the "-?" and also for which validation this regular expression is used. Thanks.

      W Offline
      W Offline
      WoutL
      wrote on last edited by
      #2

      The -? means a minus (-) or none minussign. I think the most simple regexp is: (^-?\d+(\.\d*)?$)|(^-?\d*(\.\d+)?$) This will allow also number like .7 and -.3 A little simpler is: ^-?\d+(\.\d*)?$ This does not allow .7 or -.3 but it will allow 0.7 and -0.3 Wout Louwers -- modified at 7:39 Thursday 8th June, 2006

      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