Hi, I have a script that checks the input for a mark and does not allow >20 numbers. How can I add to the following code an additional check for the period '.' so that it won't let the user input eg. 12.4? function markvalidate(count) { Form=document.addmarkfrm; valid=true; for(j=1; j<=count; j++) { if(document.getElementById('mark-'+j).value=="") { alert("Please Enter Mark"+j); document.getElementById('mark-'+j).focus(); valid=false; return false;} else if(document.getElementById('mark-'+j).value!="") { if (!Markcheck(document.getElementById('mark-'+j).value) ) { document.getElementById('mark-'+j).focus(); valid=false; return false;}} } return valid; } function Markcheck(val) { if(val > 20) { alert("Please Enter the Mark Below 20"); return false; }else{ return true; } } function checkuploads(mark) { for (i=0; i<document.addmarkfrm[0].mark.length; i++) { if (document.addmarkfrm[0].mark[i].value!= '') { user_input = document.addmarkfrm[0].mark[i].value; } } if (user_input) { return false; } } Code (markup): Any help will be appreciated
What you need is a numeric validation (you don't want to permit input like 2~1,3 too; right?) The following check does a numeric validation if(val.search("[^0-9]")>=0) { //error } Code (markup): This JavaScript form validation script helps in adding validations quickly.
I want to insert only numbers from 0.01 to 20.00 and as where I leave the period is used instead of the comma for decimal numbers
Man use the "indexOf()"! javascript:var x=prompt("Enter any string");if(x.indexOf(".")==-1){alert("Good there is no '.'")}else{alert("No '.' allowed!")} Simple!