Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi, how do you validate 1st 6 id number with date of birth in web form.plz help
Posted
Comments
Anuj Banka 7-Dec-11 3:17am    
Your requirement is not clear

Use Substring method to get the first 6 characters

C#
string id = "021345052";

id = id.Substring(0, 6);


Regards,
Eduard
 
Share this answer
 
From the name I guess you are South African, so here is some javascript code for validating an RSA id. It checks for valid date and the checkdigit at the end

JavaScript
function ValidateRSAIDNo(id) {
       try {
           if (id.length != 13) return false;

           var y1o = id.substring(0, 1)
           var y2e = id.substring(1, 2)
           var m1o = id.substring(2, 3)
           var m2e = id.substring(3, 4)
           var d1o = id.substring(4, 5)
           var d2e = id.substring(5, 6)
           var go = id.substring(6, 7)
           var s1e = id.substring(7, 8)
           var s2o = id.substring(8, 9)
           var s3e = id.substring(9, 10)
           var co = id.substring(10, 11)
           var ae = id.substring(11, 12)
           var z = id.substring(12, 13)

           var A = 0;
           A = parseInt(A) + parseInt(y1o) + parseInt(m1o) + parseInt(d1o) + parseInt(go) + parseInt(s2o) + parseInt(co);
           var B1 = y2e + m2e + d2e + s1e + s3e + ae;
           var B2 = B1 * 2;
           var i = 0;
           var B3 = 0;
           var B2string = B2.toString();
           while (B2string.length > i) {
               var x = B2string.substring(i, i + 1);
               B3 = B3 + parseInt(x);
               i = i + 1;
           }

           var C = A + B3;
           var Cstring = C.toString();
           var secNo = Cstring.substring(1, 2);
           var D = 10 - parseInt(secNo);
           while (D >= 10) D = D - 10;
           if (D == z) {
               //test for valid date in 1900
               var valid = true;
               var bd = new Date('19' + y1o + y2e, parseInt(m1o + m2e) - 1, d1o + d2e);
               if ((bd == 'NaN') | (bd == 'Invalid Date')) valid = false;
               else if (bd.getFullYear() != parseInt('19' + y1o + y2e)) valid = false;
               else if (bd.getMonth() + 1 != parseInt(m1o + m2e)) valid = false;
               else if (bd.getDate() != parseInt(d1o + d2e)) valid = false;
               //if invalid test again in 2000
               valid = true;
               bd = new Date('20' + y1o + y2e, parseInt(m1o + m2e) - 1, d1o + d2e);
               if ((bd == 'NaN') | (bd == 'Invalid Date')) valid = false;
               else if (bd.getFullYear() != parseInt('20' + y1o + y2e)) valid = false;
               else if (bd.getMonth() + 1 != parseInt(m1o + m2e)) valid = false;
               else if (bd.getDate() != parseInt(d1o + d2e)) valid = false;
               //return result
               return valid;
           }
           else {
               return false;
           }
       }
       catch (e) {
           return false;
       }
   }
 
Share this answer
 
This is the second time you ask this question Link

It was answered before.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900