0

I can see the below regular expression in the code ...

if (amount.matches("[-+]?[0-9]*\\.?[0-9]+")) return true;

now my query is that what this regular expression represent that amount should be numeric and what validation it will check

1 Answers1

1

Your regex works like this :

       "[-+]?[0-9]*\\.?[0-9]+"
[-+]? --> either a `+` or `-` or nothing. Followed by
[0-9]* --> any number of digits (* implies greedy check). Followed by  
`\\.?` --> 0 or 1 `.` (matched literally. ). Followed by 
[0-9]+ --> one or more digits 

demo here

TheLostMind
  • 35,966
  • 12
  • 68
  • 104