Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Validate ID Number
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Zamani
Validate ID Number
1 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


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


Advertisement
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: a@a.com in the above email id i want to validate whether a.com is present
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
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
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
id
id  how to find date of birth and gender in id in html with the help of javascript
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 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
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
long validate
long validate  How to validate long type
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
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 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
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 select option jquery
validate select option jquery  How to Validate select option in JQuery
validate() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
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
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
<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
 

 

 

DMCA.com