PDA

View Full Version : Numeric Validation


tsbarnes
03-24-2003, 09:46 PM
I am trrying to implement numeric validation on one of my form fields but I do want to allow periods(.) and Dollar Signs($). How would I do this?

Thanks in advance,

tsbarnes

boywonder
03-24-2003, 11:45 PM
Play around with this a bit

<script language="javascript" type="text/javascript">
<!--
var str = "$234.23";
alert((/[^\d$\.]/.test(str))?'illegal characters':'no illegal characters');
//-->
</script>

liorean
03-25-2003, 12:20 AM
str=[string FormFieldValue];
var re=/^\$?[0-9.]+$/;
alert(str.match(re)?'legal':'illegal');

cyphre
05-09-2003, 01:58 AM
hello all... i just found this forum today to get some javascript help. i was looking for some help with this exact issue however i do not want decimal points. i have quantity fields and i do not want anyone to enter letters or any other characters. could anyone help me with this. i did find a little script on http://www.mattkruse.com/javascript/validations/source.html)

function isBlank(val){
if(val==null){return true;}
for(var i=0;i<val.length;i++) {
if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
}
return true;
}

function isInteger(val){
if (isBlank(val)){return false;}
for(var i=0;i<val.length;i++){
if(!isDigit(val.charAt(i))){return false;}
}
return true;
}
function isDigit(num) {
if (num.length>1){return false;}
var string="1234567890";
if (string.indexOf(num)!=-1){return true;}
return false;
}

now this will give me a true or false alert. i just want it to alert when someone enters and illigal character. i use the onBlur for this function.

onBlur="MaterialTotals();alert(isInteger(SamplesForm.L65.value));"

any help would be greatly appreciated.

thanks,
daniel grimm