You like making your users mad, huh? (In email, often anything with two exclamation points [!!] is picked up by 'flame' filters.) The more the chance of 'being scolded' by a form (politely or otherwise), the less likely people will be to continue using it. A user friendly form will self correct where possible. Very well though, I at least toned down the language in the alert a little:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function formatThous(num, places){
var f = formatThous;
if (!num) return '';
else if (isNaN(parseFloat(num)) || (f.rejectSign && /(\+)|(-)/.test(num.toString(10))) || num.toString(10).split('.').length > 2){
alert (f.errorMessage);
return num;
}
else if (num.toString(10).split('.').length > 1 && num.toString(10).split('.')[1].length > places){
alert ('Invalid Data: Do Not Exceed ' + places + ' Decimal Places, Please.');
return num;
}
var l, c = 1, t = '',
sign = /^(\+)|(-)/.test(num.toString(10).charAt(0)) && !f.stripSign? num.toString(10).charAt(0) : '';
num = num.toString(10).replace(/[^\d\.]/g, '').split('.');
l = num[0].length-1;
while (l + 1){
t = c%3||!l? num[0].charAt(l) + t : ',' + num[0].charAt(l) + t;
l--;
c++;
}
return sign + t + (num[1] && num[1].length >= 2? '.' + num[1] : num[1] && num[1].length == 1? '.' + num[1] + '0' : '.00');
}
// Configuration:
formatThous.errorMessage = 'Numerals Only With a Maximum of One Decimal Point Symbol Only, Please.'; // Message to Alert onerror
formatThous.rejectSign = true; // set to true to reject attempts use +/- signs, false to either strip or preserve these signs
formatThous.stripSign = true; // requires rejectSign = false, set to true to strip these signs, false to preserve them
</script>
</head>
<body>
<input type="text" onblur="this.value = formatThous(this.value, 4);">
</body>
</html>
If there are any more changes you would like, please make a complete list instead of asking for them one at a time.
Bookmarks