wasabi3689
asked on
Date validation - no empty and null input allowed, How?
I have the following JS
<script language = "Javascript">
......
function ValidateForm(){
var dt=document.NetFlow.BegDat e
var dt2=document.NetFlow.EndDa te
var dt3= document.NetFlow.Num_Resul ts
if (isDate(dt.value)==false)
{
dt.focus()
return false
}
else if (isDate(dt2.value)==false)
{
dt2.focus()
return false
}
else if(dt3.value.match(/[^0-9] /))
{
alert("Invalid data format.\nOnly numbers are allowed.");
dt3.focus()
return false
}
return true
}
function ValidateIntlNumber(fld) {
if (fld.value.match(/[^0-9]/) ) {
alert ('Only numbers are permitted');
// Un comment the next line is you want to remove the non-numbers automatically
fld.value=fld.value.replac e(/[^0-9]/ g,'');
}
}
</script>
........
<label>Degree of Imbalence: <input name="DegImb" type="text" size="3" value="65" onkeyup="ValidateIntlNumbe r(this);"> ( enter as 50% ) </label>
<label>Total Flows:<input name="TotalFlowImb" type="text" size="3" value="10" onkeyup="ValidateIntlNumbe r(this);" > ( enter as )</label>
<label># of Results: <input type="text" name="Num_Results" size="3" maxlength="3" value="25" onkeyup="ValidateIntlNumbe r(this);" ></label>
<label>Date Range: <input type="text" size="20" maxlength="30" name= "BegDate" value="<%=y%>" > - <input type="text" size="20" maxlength="30" name="EndDate" value=<%=s%> > ( enter as mm/dd/yyyy)</label>
</div>
.......
I have one question to improve my code
I don't want null value or empty value be stayed in the any fields above. That means user must input a valid data into the field, can not leave null, blank before he submits the form. How to do that?
<script language = "Javascript">
......
function ValidateForm(){
var dt=document.NetFlow.BegDat
var dt2=document.NetFlow.EndDa
var dt3= document.NetFlow.Num_Resul
if (isDate(dt.value)==false)
{
dt.focus()
return false
}
else if (isDate(dt2.value)==false)
{
dt2.focus()
return false
}
else if(dt3.value.match(/[^0-9]
{
alert("Invalid data format.\nOnly numbers are allowed.");
dt3.focus()
return false
}
return true
}
function ValidateIntlNumber(fld) {
if (fld.value.match(/[^0-9]/)
alert ('Only numbers are permitted');
// Un comment the next line is you want to remove the non-numbers automatically
fld.value=fld.value.replac
}
}
</script>
........
<label>Degree of Imbalence: <input name="DegImb" type="text" size="3" value="65" onkeyup="ValidateIntlNumbe
<label>Total Flows:<input name="TotalFlowImb" type="text" size="3" value="10" onkeyup="ValidateIntlNumbe
<label># of Results: <input type="text" name="Num_Results" size="3" maxlength="3" value="25" onkeyup="ValidateIntlNumbe
<label>Date Range: <input type="text" size="20" maxlength="30" name= "BegDate" value="<%=y%>" > - <input type="text" size="20" maxlength="30" name="EndDate" value=<%=s%> > ( enter as mm/dd/yyyy)</label>
</div>
.......
I have one question to improve my code
I don't want null value or empty value be stayed in the any fields above. That means user must input a valid data into the field, can not leave null, blank before he submits the form. How to do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is your server side Java? You can also use Struts validator framework. Or .NET validator controls in case of ASP .NET. However, to realize the advantage of distributed client-server processing, it might be better to do it at the client side itself using the code already provided.