Trevor Ackermann Trevor Ackermann - 4 months ago 22
PHP Question

PHP Forms with Min Characters Requirement

I have the following Validate form that request that a person completes all the relevant blocks on the form. I am trying to have one Block have a min number of characters for that specific block only. Below is my current code

<script>
function validateForm()
{
var a=document.forms["lbs_trace"]["lbs_reason"].value;
var b=document.forms["lbs_trace"]["lbs_for"].value;
var c=document.forms["lbs_trace"]["lbs_type"].value;
var x=document.forms["lbs_trace"]["lbs_case"].value;
var y=document.forms["lbs_trace"]["lbs_terms"].value;
var count = 0;
if (!(a==null|| a==""))
{
count++;
}
if (!(b==null|| b==""))
{
count++;
}
if (!(c==null|| c==""))
{
count++;
}
if (!(x==null || x==""))
{
count++;
}
if (!(y==null || y==""))
{
count++;
}
if(count < 5){
alert("Please assure that the following has been completed, CASE TYPE, REQUESTED BY, DESCRIPTION, CASE NUMBER and TERMS AND CONDITIONS ARE TICKED");
return false;
}



}
</script>


In VAR A I want a min of 30 Characters to be entered before continuing to process the form

Answer

Maybe use a javascript tag, this isn't php. Here's how to validate length:

if (!(a==null || a.length < 30))