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
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
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
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
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
Maven Repository/Dependency: commons-jelly-tags-validate | commons-jelly-tags-validate
Maven Repository/Dependency of Group ID commons-jelly-tags-validate and Artifact ID commons-jelly-tags-validate. Latest version of commons-jelly-tags-validate:commons-jelly-tags-validate dependencies. # Version
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
Maven Repository/Dependency: com.feiynn | feiynn-validate
Maven Repository/Dependency of Group ID com.feiynn and Artifact ID feiynn-validate. Latest version of com.feiynn:feiynn-validate dependencies. # Version Release Date You can read more
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
long validate
long validate  How to validate long type
Maven Repository/Dependency: cloud.agileframework | agile-validate
Maven Repository/Dependency of Group ID cloud.agileframework and Artifact ID agile-validate. Latest version of cloud.agileframework:agile-validate dependencies. # Version Release Date
id
id  how to find date of birth and gender in id in html with the help of javascript
Maven Repository/Dependency: org.aoju | bus-validate
Maven Repository/Dependency of Group ID org.aoju and Artifact ID bus-validate. Latest version of org.aoju:bus-validate dependencies. # Version Release Date 1 8.0.0 12
Maven Repository/Dependency: commons-jelly | commons-jelly-tags-validate
Maven Repository/Dependency of Group ID commons-jelly and Artifact ID commons-jelly-tags-validate. Latest version of commons-jelly:commons-jelly-tags-validate dependencies. # Version Release Date
VALIDATE
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" />
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
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
number - Java Interview Questions
number  apka number kya hai aap apna number mera id per send ker do
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
buzz number
buzz number  buzz number
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
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
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')">
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
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
the number of parameters
the number of parameters  How do I find out the number of parameters passed into function
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array
prime number
prime number  check prime number using if statement   Java Check Prime Number

Ads