Hello, I’m hoping someone is able to point me in the right direction. Basically I’ve got a form in which I’m using a Javascript validation script from [url]http://www.webcheatsheet.com/javascript/form_validation.php
Although I’ve been successful in validating most of the fields in my form, I’m having problems ensuring some fields only allow numerical values, i.e. £ amounts. I’m using the script below and although it works, it requires the field to be completed and ideally I’m looking for either the field to be empty or to only allow numbers.
Thanks in advance
Richard
</script>
<script type=”text/javascript”>
function validateFormOnSubmit(theForm) {
var reason = “”;
reason += validateAmt(theForm.TimeAtAddress_1stApp);
if (reason != “”) {
alert(“Some fields need attention:n” + reason);
return false;
}
return true;
}
function validateAmt(fld) {
var error = “”;
var stripped = fld.value.replace(/[().–
if (isNaN(parseInt(stripped))) {
error = “A number field contains illegal characters. Please see the highlighted field/s.n”;
fld.style.background = ‘Yellow’;
} else {
fld.style.background = ‘White’;
}
return error;
}
</script>