Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  39] [ 2]  / answers: 1 / hits: 29189  / 13 Years ago, thu, october 13, 2011, 12:00:00

I want to test for this input:
[an optional negative sign] 2 digits [an optional . and an optional digit] like this:



-34 or -34.5333 or 34.53333 or 34 in JavaScript



This is what I came up with but it doesn't work!



/^(-)d{2}(.d{1})$/


Can someone please help me?


More From » jquery

 Answers
8

Try this regex:



/^-?d{2}(.d+)?$/

[#89640] Wednesday, October 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juand

Total Points: 366
Total Questions: 95
Total Answers: 90

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;