Hi all, I have a function which I use to limit form inputs to numbers only, or number and decimals depending on the field. Allowing decimals and numbers is easy enough, but I am trying to take it a step further and allow only one decimal, while also making sure that decimal is not the first character in the field. I have successfully allowed only one decimal, and I have also made it so a decimal will only be allowed if "0" is the first digit, but I cannot get it to allow a decimal when ANY number is the first digit for some reason. I could make it work if I made a massive if
statement, but I am trying to avoid that. Any suggestions?
// this allows only one decimal, and only if the first character of the field is a zero
else if ((('.').indexOf(keychar) > -1) && field == document.form.start_pay && document.form.start_pay.value.indexOf('.') <= -1 && document.form.start_pay.value.charAt(0) == ('0')){
return true;
}