We help IT Professionals succeed at work.
Get Started

Date validation - no empty and null input allowed, How?

wasabi3689 asked
Last Modified: 2008-02-01
I have the following JS

<script language = "Javascript">
function ValidateForm(){
      var dt=document.NetFlow.BegDate
        var dt2=document.NetFlow.EndDate
        var dt3= document.NetFlow.Num_Results
      if (isDate(dt.value)==false)
            return false
         else if (isDate(dt2.value)==false)
            return false
       else if(dt3.value.match(/[^0-9]/))
        alert("Invalid data format.\nOnly numbers are allowed.");
        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


                    <label>Degree of Imbalence: <input name="DegImb" type="text" size="3" value="65" onkeyup="ValidateIntlNumber(this);"> ( enter as 50% )&nbsp; &nbsp; </label>
                    <label>Total Flows:<input name="TotalFlowImb" type="text" size="3" value="10" onkeyup="ValidateIntlNumber(this);" > ( enter as  )</label>
 <label># of Results: <input type="text" name="Num_Results" size="3" maxlength="3" value="25" onkeyup="ValidateIntlNumber(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>


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?
Watch Question
Distinguished Expert 2020
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE