I need to change a South African ID number to the date of birth (DOB)dd/mm/yyyy using javascript
example of ID Number - 0203185149088.
My code gives it as 18/03/02 instead of 18/03/2002 and if ID No is 6202185155087 then i get 18/02/62 and not 18/02/1962
The years before 2000 and after needs to be added please
dd/mm/yyyy
Please assist - <form>
-
<input type="text" name="idno" id="idno" value="" placeholder="ID Number" onkeyup="dateOfBirthsum();" />
-
<input type="text" name="dob" id="dob" placeholder="birthdate"/>
-
-
</form>
javascript - <script>
-
-
function dateOfBirthsum()
-
{ var idnumInput = document.getElementById('idno').value;
-
-
var dateDay = idnumInput.substring(4,6);
-
var dateMonth = idnumInput.substring(2,4);
-
var dateYear = idnumInput.substring(0,2);
-
var result = dateDay + "/" + dateMonth + "/" + dateYear;
-
document.getElementById('dob').value = result;
-
}
-
</script>
I got this code somewhere but cannot add it - var year = id_number.substr ( 0 , 2 );
-
var nowYearNotCentury = currentTime.getFullYear() + '';
-
nowYearNotCentury = nowYearNotCentury.substr(2,2);
-
if (year <= nowYearNotCentury){
-
date = '20' + year+ "-" + id_number.substr(2, 2) + "-" + id_number.substr(4, 2);
-
} else {
-
date = '19' + year+ "-" + id_number.substr(2, 2) + "-" + id_number.substr(4, 2);
-
}//end if
4 1351
After 3 hours of struggling, i got it working. Anybody else needing a very basic solution, here it is - <body>
-
<form>
-
<input type="text" name="idno" id="idno" value="" placeholder="ID Number" onkeyup="dateOfBirthsum();" />
-
-
<input type="text" name="dob2" id="dob2" placeholder="birthdate2"/>
-
</form>
-
<script>
-
-
function dateOfBirthsum()
-
{ var idnumInput = document.getElementById('idno').value;
-
-
var dateDay = idnumInput.substring(4,6);
-
var dateMonth = idnumInput.substring(2,4);
-
var dateYear = idnumInput.substring(0,2);
-
-
var dateYear1 = '19' + dateYear;
-
var dateYear2 = '20' + dateYear;
-
var Year1 = dateYear;
-
var Year2 = dateYear;
-
var years = new Date();
-
var dateYear3 = years.getFullYear();
-
var dateYear3a = idnumInput.substring(0,2);
-
-
if (dateYear1 < dateYear3a){
-
result3 = dateDay + "/" + dateMonth + "/" + '19' + dateYear;
-
} else {
-
result3 = dateDay + "/" + dateMonth + "/" + '20' + dateYear;
-
}
-
-
document.getElementById('dob2').value = result3;
-
-
}
-
</script>
out of curiousity, how do you determine the DoB for people older than 100 years?
Thx for comment. It is for a cycling races online registration site. I don't expect to many 101 year old cyclist's to enter.
OK. please keep us updated, if they do.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sansanee |
last post by:
Hi,
I am wondering if there is any format string for phone number. Just like
those dd:mm:yyyy or C for currency. Can anyone enlighten me?
Thank you in advance,
Sunny
|
by: Servé Lau |
last post by:
suppose I want to use sscanf get the functionname from a function prototype.
Is the following format string correct then?
char funcname;
char *p = "func(void)";
sscanf(p, "%s", funcname);...
|
by: Özgür Aytekin |
last post by:
How can I display the hundredth of a second or which is the correct format
string?
I use now {0:yyyy-MM-dd HH:mm:ss} and this display the following
information:
2004-08-04 21:49:21... But I...
|
by: Eddy Soeparmin |
last post by:
Hi,
I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On
myGrid1 - Properties - Columns - myColumn1 - Text format string:
I tried to put 'mm/dd/yyyy' in there and it displays...
|
by: stathisgotsis |
last post by:
Hello everyone,
Trusting K&R2 i thought until recently that spaces are ignored in
scanf's format string. Reading arguments to the contrary confused me a
little. So i now ask:
Is...
|
by: gregpinero |
last post by:
I might just be being dumb tonight, but why doesn't this work:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: not enough arguments for format string
(I'm in Python...
|
by: stainless |
last post by:
I know this is probably simple but I cannot find a method of
converting a date string into a format that matches the DatePicker
format in C#
eg string "20080131" converted to "31 January 2008"
...
|
by: gregcm |
last post by:
I've got a custom control that is trying to allow the user to enter a
DateTime in a definable format and I was wondering if there was an
easy way to alter the look of said control based on the...
|
by: moondaddy |
last post by:
I need to format a string to it always has 2 digits in it. I'm getting the
month like this:
DateTime.Now.Month.ToString()
Right now since it's August, this returns a string of "8", however, I...
|
by: Andrus |
last post by:
How to create format string for decimal data type
which shows blank for zero and default format otherwize ?
I tried format string "f;f;#" but this shows f for nonzero numbers.
Andrus.
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |