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
what your regEx ( /^(-)\d{2}(.d{1})$/ ) does is:
Start with requiring the negative and then correctly your requiring two digits, then with the "." your requiring any character, you should strict it to the symbol with "\", and finally comes one digit.
correct example code would be:
var str = '-34.23';
pat=/^\-?\d{2}(\.(\d)*)?$/g;
str.match(pat);
More testable example: http://jsfiddle.net/GUFgS/1/
use the "?" after the group to make that match an option i.e (\.\d*)?