This sounds like it would be a fairly common issue, but I’ve searched a lot and can’t find anything that works. I’m using the jquery validate plug-in to validate form input. There’s a field which needs to accept only negative numbers (can be whole integers or decimals but must be less than zero).
I’ve tried doing something like this:
$.validator.addClassRules("negativeNumber", { range: [-1000000000, 0] });
…which works okay, but the validation error is horrible (“Please enter a number between -1000000000 and 0”) – I’d like it to just say “Please enter a negative number”.
Could anyone point me in the direction of a regex that only allows negative numbers?
Many thanks folks…
Instead of a regex, you can add a custom validation method, which I believe is easier to read.