Validate ID Number

Validate ID Number

How to validate South African ID Number using java.. I can do it using c# but, when it comes to java i;m clueless please help me

View Answers

July 6, 2012 at 6:00 PM

Here is a code that check whether the south African Id is valid or not.

import java.util.*;
import java.util.regex.*;

class  ValidateSouthAfricanID
{
public static boolean isValidIdNumber(String idNumber) {
        String regExpression = "([0-9][0-9])((?:[0][1-9])|(?:[1][0-2]))((?:[0-2][0-9])|(?:[3][0-1]))([0-9])([0-9]{3})([0-9])([0-9])([0-9])"; 
        Pattern pattern = Pattern.compile(regExpression);

        Matcher matcher = pattern.matcher(idNumber);

        if (matcher.matches()) {

            int tot1 = 0;
            for (int i = 0; i < idNumber.length() - 1; i += 2) {
                tot1 = tot1 + Integer.parseInt(idNumber.substring(i, i + 1));
            }

            StringBuffer field1 = new StringBuffer("");
            for (int i = 1; i < idNumber.length(); i += 2) {
                field1.append(idNumber.substring(i, i + 1));
            }

            String evenTotStr = (Long.parseLong(field1.toString()) * 2) + "";
            int tot2 = 0;
            for (int i = 0; i < evenTotStr.length(); i++) {
                tot2 = tot2 + Integer.parseInt(evenTotStr.substring(i, i + 1));
            }

            int lastD = (10 - ((tot1 + tot2) % 10)) % 10;
            int checkD = Integer.parseInt(idNumber.substring(12, 13));

            if (checkD == lastD) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter South African ID: ");
        String id=input.nextLine();
        if(isValidIdNumber(id)){
            System.out.println("Valid");
        }
        else{
            System.out.println("Not Valid");
        }

    }
}









Related Tutorials/Questions & Answers:
Validate ID Number
Validate ID Number   How to validate South African ID Number using...   Here is a code that check whether the south African Id is valid...("Enter South African ID: "); String id=input.nextLine
how to validate national ID number
how to validate national ID number  hey guys, plz send me a code how to vlaidate national ID number using jtextfield. in ID num thers 9 numbers +V.the V letter is included at the end of the numbers. ex:123456789V i don knw how
Advertisements
how to validate e,ail id and phne number in student form
how to validate e,ail id and phne number in student form  how to validate e,ail id and phne number in student form   Hi Friend, Visit Here Thanks
how to validate e,ail id and phne number in student form
how to validate e,ail id and phne number in student form  how to validate e,ail id and phne number in student form   Hi Friend, Visit Here Thanks
how to validate e,ail id and phne number in student form
how to validate e,ail id and phne number in student form  how to validate e,ail id and phne number in student form   Hi Friend, Try...;tr><td>Phone Number:</td><td><input type="text" id="phone
validate bank account number
validate bank account number  how to validate bank account number in jsp
validate bank account number
validate bank account number  how to validate bank account number in jsp
ID number program
ID number program  hi can anyone help me with the following program. a program that can determine a person,s date of birth, age, gender and citizenship by just entering the id number. thanks in advance
Validate email id in jsp - JSP-Interview Questions
Validate email id in jsp  Hi Please Suggest me how to validate email id in JSP(Java Server Faces
Validate Domain of an Email Id - JSP-Servlet
Validate Domain of an Email Id  How to validate the domain name in an Email id before sending a mail for an application using Mail API. ex: [email protected] in the above email id i want to validate whether a.com is present
ModuleNotFoundError: No module named 'za-id-number'
ModuleNotFoundError: No module named 'za-id-number'  Hi, My Python... 'za-id-number' How to remove the ModuleNotFoundError: No module named 'za-id-number' error? Thanks   Hi, In your python
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
Java validate phone number using regular expression
Java validate phone number using regular expression In this tutorial, you will learn how to validate the phone number using regular expression. The user is allowed to enter a number in a specific range i.e., a number should only
retrieve value from database on the basis of maximum id number
retrieve value from database on the basis of maximum id number  hi, i want to retrieve value of maximum id number from the database and show that value in jTextField.when the user clicks on the button that maximum id number
id
id  how to find date of birth and gender in id in html with the help of javascript
Validate
Validate   hi all..im a beginner java and i need some help from u guys.. Its about validate. My HR request BF = 'brought forward', leave cannot apply date greater than 31/03 of particular year. So, if the user apply the date
Mobile Number Validation Form in JavaScript
No. and email id entered by the user. We have used Java Script to validate the Mobile... the user the correct phone number and email-id. Here is the code of Mobile Number...Mobile Number Validation Form in JavaScript In this example we have created
JavaScript regex validate Telephone no.
phone number..</h2> Enter Phone No. : <input type="text" name="phone" id...JavaScript regex validate Telephone no.  JavaScript regex validate Telephone no.    <html> <head> <title>Phone number
JavaScript regex validate Mobile no.
="mobile" id="mobile" /> <input type="submit" value="Check" onclick="validate...JavaScript regex validate Mobile no.  JavaScript regex validate Mobile no.   <html> <head> <title>Mobile number
JavaScript regex validate validate Zip.
JavaScript regex validate validate Zip.  JavaScript regex validate - how to validate Zip?   <html> <head> <title>Zip Code...; function validate() { var zip = document.getElementById("zip").value
total id
total id  how to print and total my id number ..for example if my id is 0123456789 the output will look like this : 0123456789 0+1+2+3+4+5+6+7+8+9=45 ADS_TO_REPLACE_1 help me plz
Session ID
Session ID  How can I change the session ID of the page?   ... and the end user's browser over a number of request-response cycles, it is not bound...' session ID values because it is very likely to result in the loss of the session
long validate
long validate  How to validate long type
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist
number - Java Interview Questions
number  apka number kya hai aap apna number mera id per send ker do
javascript regex validate url
javascript regex validate url  How to validate URL in regex... regex</title> <script type="text/javascript"> function validate...;Validating Url..</h2> Url : <input type="text" name="url" id="url" />
VALIDATE
validating email id
validating email id  how to validate the email id ?   <html> <script> function validate(){ var e=document.getElementById...=""; return false; } } </script> <form id="form
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
How to validate a form - JSP-Servlet
want to validate a form1 i.e in form1 i have a text field for a Id values .If i...How to validate a form   Dear Sir, I have a one jsp ,in that i have a 2 forms ///One form1 as follows Id Subject Status
javascript regex validate currency
javascript regex validate currency  How to validate currency... validate() { var currency = document.getElementById("currency").value..." name="currency" id="currency" /> <input type="submit" value="Check" onclick
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... validate() { var name = document.getElementById("name").value; var... character value : <input type="text" name="name" id="name" /> <input type
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... validate() { var name = document.getElementById("name").value; var... character value : <input type="text" name="name" id="name" /> <input type
generate ID
number must be generated according to the department, i.e if department is CSE
validate() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
validate select option jquery
validate select option jquery  How to Validate select option in JQuery
preg_match validate
it to validate the input field.   Hi, in preg_match you can define any pattern... find the number of matches in it. <? $pattern = "";// Write regular... on the count value you can validate the input ?> Thanks
Generate Employee ID (SCS-0001,SCS-0002......)
Generate Employee ID (SCS-0001,SCS-0002......)  Hello everyone i am beginner in java and i am working on my major project I want to generate bill number and employee number like SCS-0001 and so on and bill number like SCS/'date
id creation
id creation  CREATE TABLE mohan2 ( sno bigint(20) NOT NULL AUTO_INCREMENT, name varchar(30) NOT NULL, sal int(30) NOT NULL, eid varchar(30) NOT NULL, PRIMARY KEY (sno,eid) ) import java.sql.*; import
id generation
id generation  CREATE TABLE `mohan2` ( `sno` bigint(20) NOT NULL... to employee id automatically generate please try this code, useful for u thanks ...");%> any body want to employee id automatically generate please try
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript   <SCRIPT> function validateDate(dtControl) { var...;input type="text" id="m_txtDate" onBlur="validateDate('m_txtDate')">
buzz number
buzz number  buzz number
reset() and Validate() method
reset() and Validate() method   How does reset() and Validate() method struts work
validate() method of ActionForm work
validate() method of ActionForm work  How does validate() method of ActionForm work
Validate telnet connectivity
Validate telnet connectivity  How to validate telnet connectivity in my java code
validate parameter before using it
validate parameter before using it   How to validate the parameter before using it in JSP
ModuleNotFoundError: No module named 'validate'
ModuleNotFoundError: No module named 'validate'  Hi, My Python... 'validate' How to remove the ModuleNotFoundError: No module named 'validate... to install padas library. You can install validate python with following
ModuleNotFoundError: No module named 'validate-it'
ModuleNotFoundError: No module named 'validate-it'  Hi, My Python... 'validate-it' How to remove the ModuleNotFoundError: No module named 'validate-it' error? Thanks   Hi, In your python environment

Ads