skip to Main Content

I have users who are pasting strings into text fields that break my calculations. I could really use some help building a Regex expression that:

  • only allows numbers 0-9
  • only allows one "-" (ascii 45) in the first position in the string
  • only allows one "." (ascii 46)
  • only allows for up to 3 decimal places after the only instance of "." (ascii 46)

2

Answers


  1. This should work:

    /^-?d*(.d{1,3})?$/
    
    Login or Signup to reply.
  2. /^-?d{1,}.?d{0,3}$/ should be working.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search