I am trying to validate currency with the following function:
function checkwages(input){
var validformat=/^\d{0,5}(\.\d{1,2})?$/;
if ( validformat.test(input)) {
// alert("$:"+ input + " test");
return true;
}
return false;
}
The goal is to make sure user enters either numbers or decimal format. It cannot be 0 or negative. However when the input field is blank this fails as 0 digits is valid in this format. However, if I change it to /^\d{1,5}(\.\d{1,2})?$/ then .21 becomes invalid and forces user to enter something like 0.21. How can I change the regex so that even .21 is considered valid number?
Thanks
the bit at the beginning looks for a non-zero anywhere in the string, but doesn’t capture it.