[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

I want to check validation on the DOB in Oracle DB

Hi

I have a jsp register page with validation, but i want to check the Date Of Birth field.
Accessing Oracle DB.
The date of birth is in the format: Day Month Year

Day is 1 - 31
Month is the first 3 letters, ie. Mar
Year is 2001

Can the year be checked between 1900 - 1993
0
acslater
Asked:
acslater
  • 8
  • 4
2 Solutions
 
Michel PlungjanIT ExpertCommented:
dob = new Date("29 Feb 1904");
alert(dob.getDate())

so it works just fine
0
 
Michel PlungjanIT ExpertCommented:
months = "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec".split(',')

function validate(dob) {
  var tDob = new Date(dob)
  var parts = dob.split(' ');
  if (isNaN(tDob)) return false
  if (parts.length !=3) return false
  if (
    parts[0] != tDob.getDate() ||
    parts[1].toLowerCase()!=months[tDob.getMonth()] ||
    parts[2] != tDob.getFullYear()
   ) return false;
}
0
 
Michel PlungjanIT ExpertCommented:
And I guess I am not reading this correctly.

<script>
dobYear = parseInt(<%= dob %>)
if (dobYear < 1900 || dobYear > 1993) document.write('Wrong year')
</script>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
acslaterAuthor Commented:
I have a script already but just want to include the DOB function and a few other small bits.

Basically,The DOB field must check that the user is born before 1993.
Sorry if I did not make it clear at the start. The above is the format that the oracle date is in.
aswell ...

    if (frm1.ID.value.length < 6) {
       alert("Please enter a Valid ID Number"); //How do I change this so that ID has to start with "E" and have exact 6 chars
       frm1.ID.focus( );
       return false;
     }
0
 
Michel PlungjanIT ExpertCommented:
 var id = frm1.ID.value;
  if (id.length != 6 || (id.length == 6 && id.charAt(0)!='E')) {
       alert("Please enter a Valid ID Number"); //How do I change this so that ID has to start with "E" and have exact 6 chars
       frm1.ID.focus( );
       return false;
     }
0
 
davidlars99Commented:
function DOB(d){
     var d1=new Date("01/01/1993");
     var d2=new Date(d);
     return (d1<d2);
}


and then check part


if (DOB("somedatevalue"))
    //  good to go
else
   // not good
0
 
acslaterAuthor Commented:
I have the following validation and form but its not checking it, and just going straight to the next page, i think i might have the form in the wrong place but not sure ....


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script>
function validateForm(frm1) {

    var id = frm1.ID.value;
  if (id.length != 6 || (id.length == 6 && id.charAt(0)!='E')) {
       alert("Please enter a Valid ID Number"); //How do I change this so that ID has to start with "E" and have exact 6 chars
       frm1.ID.focus( );
       return false;
     }

var pattern = (/^[a-zA-Z|\s* | -]*$/g);
var name = document.frm1.Name.value;

if (frm1.Name.value.length < 4 ) {
alert("Please enter Employees' Name");  //Employee name letters only and minimum of 4
       frm1.Name.focus( );
       return false;
}

else {
if (!pattern.test(name)){
   alert("Please Re-Enter Employees' Name");
   frm1.Name.focus( );
   return false;
   }
 }

if (frm1.Address.value.length <10) {
   alert("Please enter an Address");   // Address minimum of 10 chars
   frm1.Address.focus( );
   return false;
   }

function DOB(d){
     var d1=new Date("01/01/1993");
     var d2=new Date(d);
     return (d1<d2);
}

and then check part

if (DOB("somedatevalue"))
     good to go
else
    not good

   if (frm1.Phone.value.length < 4) {
   alert("Please enter your Phone No.");  // Phone Number minimum of 4 chars
   frm1.Phone.focus( );
   return false;
   }
     
         var pattern = /^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$/g
    if(!frm1.Email.value.match(pattern)){
        alert('Enter a valid email address');  //Email has to be correct format
        frm1.Email.focus();
        return false;
    }
   var pattern = (/^[a-zA-Z|\s* | -]*$/g);
var firstname = document.frm1.FirstName.value;

if (frm1.Project.value.length == 6) {
alert("Please enter the Project name");   // Project d be exact 6 chars including E
       frm1.Project.focus( );
       return false;
}
else {
if (!pattern.test(project)){
   alert("Please Re-Enter the Project name");
   frm1.Project.focus( );
   return false;
   }
 }
     if (frm1.Start.value.length < 5) {
       alert("Please enter a Start Date");  // Start date has to be in the format DAY-Month-Year 15-Mar-1994
       frm1.Start.focus( );
       return false;
     }
 
     if (frm1.Bank.value.length < 8) {
       alert("Please enter a Valid Bank Number");   // Bank number has to be 8 digits
       frm1.Bank.focus( );
       return false;
     }

}
    return true;
}
</script>

</head>

<body>

<table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
        <form name="frm1" method="post" action="registered.jsp" onSubmit="return validateForm(frm1)">
        <tr>
          <td width="167" rowspan="3" valign="top" bgcolor="8FBEE8">&nbsp;          </td>
          <td colspan="2" align="center"><table width="95%" border="0" cellpadding="5" cellspacing="0" class="text">
              <tr>
                <td class="text"><font color="#000000"><span class="style1"><br>
                  Enter the following details to register a new employee
                  </span><br>
                  <br>
                </font></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td width="588" align="center">
               
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                        <td width="17%"><strong>ID No:</strong></td>
                    <td width="83%"><input name="ID" type="text" id="ID"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                        <td width="17%"><strong>Name:</strong></td>
                    <td width="83%"><input name="Name" type="text" id="Name"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Address:</strong></td>
                        <td width="83%"><input name="Address" type="text" id="Address"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
                                  <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>D/O/B:</strong></td>
                        <td width="83%"><input name="DOB" type="text" id="DOB"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Phone:</strong></td>
                        <td width="83%"><input name="Phone" type="text" id="Phone"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Email:</strong></td>
                        <td width="83%"><input name="Email" type="text" id="Email"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Project:</strong></td>
                        <td width="83%"><input name="Project" type="text" id="Project"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Start Date:</strong></td>
                        <td width="83%"><input name="Start" type="text" id="Start"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Bank No:</strong></td>
                        <td width="83%"><input name="Bank" type="text" id="Bank"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <p>
            </p>
              <p>
                <input type="submit" name="Submit" value="Submit">
                <br>
              </p>          
          <td width="15" align="center" valign="top">&nbsp;
       
        <tr>
          <td colspan="2" valign="bottom"><table width="82%" border="0" cellspacing="0" cellpadding="8">
              <tr>
                <td align="center" valign="bottom"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">&copy;
                  2005 Ltd.</font></td>
              </tr>
            </table></td>
        </tr>
</form>
      </table>

</body>
</html>
0
 
Michel PlungjanIT ExpertCommented:
This is not valid javascript

and then check part

if (DOB("somedatevalue"))
     good to go
else
    not good

actually you just dropped the  script in the middle of another function that will not work

0
 
Michel PlungjanIT ExpertCommented:
Several other bugs fixed. I hope I got them all


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script>
function DOB(d){
     var d1=new Date("01/01/1993");
     var d2=new Date(d);
     return (d1<d2);
}

function validateForm(frm1) {

  var id = frm1.ID.value;
  if (id.length != 6 || (id.length == 6 && id.charAt(0)!='E')) {
    alert("Please enter a Valid ID Number");
    frm1.ID.focus( );
    return false;
  }

  var pattern = (/^[a-zA-Z|\s* | -]*$/g);
  var name = frm1.Name.value;
  if (name.length < 4 ) {
    alert("Please enter Employees' Name");  //Employee name letters only and minimum of 4
    frm1.Name.focus( );
    return false;
  }
  else if (!pattern.test(name)){
   alert("Please Re-Enter Employees' Name");
   frm1.Name.focus( );
   return false;
 }

  if (frm1.Address.value.length <10) {
    alert("Please enter an Address");   // Address minimum of 10 chars
    frm1.Address.focus( );
    return false;
  }
 
  if (!DOB(frm1.DOB.value)) {
    alert("Please enter an date of birth < 1993");
    frm1.DOB.focus( );
    return false;
  }

  if (frm1.Phone.value.length < 4) {
    alert("Please enter your Phone No.");  // Phone Number minimum of 4 chars
    frm1.Phone.focus( );
    return false;
  }
     
  var pattern = /^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$/g
  if(!frm1.Email.value.match(pattern)){
    alert('Enter a valid email address');  //Email has to be correct format
    frm1.Email.focus();
    return false;
  }
  var pattern = (/^[a-zA-Z|\s* | -]*$/g);
  var project = frm1.Project.value;
  if (project.length == 6) {
    alert("Please enter the Project name");   // Project d be exact 6 chars including E
    frm1.Project.focus( );
    return false;
  }
  else if (!pattern.test(project)){
    alert("Please Re-Enter the Project name");
    frm1.Project.focus( );
    return false;
  }
  if (frm1.Start.value.length < 5) {
    alert("Please enter a Start Date");  // Start date has to be in the format DAY-Month-Year 15-Mar-1994
    frm1.Start.focus( );
    return false;
  }
 
  if (frm1.Bank.value.length < 8) {
    alert("Please enter a Valid Bank Number");   // Bank number has to be 8 digits
    frm1.Bank.focus( );
    return false;
  }

  return true;
}
</script>

</head>

<body>

<table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
       <form name="frm1" method="post" action="registered.jsp" onSubmit="return validateForm(frm1)">
        <tr>
          <td width="167" rowspan="3" valign="top" bgcolor="8FBEE8">&nbsp;          </td>
          <td colspan="2" align="center"><table width="95%" border="0" cellpadding="5" cellspacing="0" class="text">
              <tr>
                <td class="text"><font color="#000000"><span class="style1"><br>
                  Enter the following details to register a new employee
                  </span><br>
                  <br>
                </font></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td width="588" align="center">
               
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                        <td width="17%"><strong>ID No:</strong></td>
                    <td width="83%"><input name="ID" type="text" id="ID"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                        <td width="17%"><strong>Name:</strong></td>
                    <td width="83%"><input name="Name" type="text" id="Name"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Address:</strong></td>
                        <td width="83%"><input name="Address" type="text" id="Address"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
                               <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>D/O/B:</strong></td>
                        <td width="83%"><input name="DOB" type="text" id="DOB"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Phone:</strong></td>
                        <td width="83%"><input name="Phone" type="text" id="Phone"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Email:</strong></td>
                        <td width="83%"><input name="Email" type="text" id="Email"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Project:</strong></td>
                        <td width="83%"><input name="Project" type="text" id="Project"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Start Date:</strong></td>
                        <td width="83%"><input name="Start" type="text" id="Start"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Bank No:</strong></td>
                        <td width="83%"><input name="Bank" type="text" id="Bank"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <p>
            </p>
              <p>
                <input type="submit" name="Submit" value="Submit">
                <br>
              </p>          
          <td width="15" align="center" valign="top">&nbsp;
       
        <tr>
          <td colspan="2" valign="bottom"><table width="82%" border="0" cellspacing="0" cellpadding="8">
              <tr>
                <td align="center" valign="bottom"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">&copy;
                  2005 Ltd.</font></td>
              </tr>
            </table></td>
        </tr>
</form>
      </table>

</body>
</html>
0
 
acslaterAuthor Commented:
Yea got most of them thanks. Just 1 or 2 small bugs. Its not checking focusing on "Project" after entering the "Email".
The Start date is not being checked properly. I've heard there is a problem with some Oracle db's that it dosen't check the date in the correct format. Don't know if this is the case.
For checking for an exact number of Values, what is used?

if (Bank.length != 8 ) {

or
  if (frm1.Bank.value.length == 8) {
0
 
Michel PlungjanIT ExpertCommented:
function DOB(d){
     var d1=new Date("01/01/1993");
     var d2=new Date(d);
     return (d1<d2); // testing that 1993 is less than date enetered. I think it should be d1>d2
}

and  
if (frm1.Bank.value.length != 8) { /* test it is NOT equal to 8 chars to give the error message */

start date needs the test I gave you


0
 
Michel PlungjanIT ExpertCommented:

so add just after
function DOB(...) {
}

months = "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec".split(',')

function isDate(dateString) {
  var tDate = new Date(dateString)
  var parts = dateString.split(' ');
  if (isNaN(tDate)) return false
  if (parts.length !=3) return false
  if (
    parts[0] != tDate.getDate() ||
    parts[1].toLowerCase()!=months[tDate.getMonth()] ||
    parts[2] != tDate.getFullYear()
   ) return false;
   return true;
}

and change
 if (frm1.Start.value.length < 5) {
to
 if (!isDate(frm1.Start.value)) {


and change
  if (project.length == 6) {
to
  if (project.length != 6) {
0
 
acslaterAuthor Commented:
nice one lads, thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now