Home Answers Viewqa Java-Beginners Validate ID Number

 
 


Zamani
Validate ID Number
1 Answer(s)      11 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

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 Pages:
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
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
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
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
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
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
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
generate ID
number must be generated according to the department, i.e if department is CSE
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" />
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
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
preg_match validate
it to validate the input field.   Hi, in preg_match you can define any pattern for matching the user input. And then use the preg_match method find the number... can validate the input ?> Thanks
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')">
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
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
How do i validate form using javascript and send data to database?
How do i validate form using javascript and send data to database?  I need a "JOIN US" form that can validate using javascript and be able to connect... into the database are: FIRST NAME, LAST NAME, EMAIL ADDRESS, PHONE NUMBER, ADDRESS
Calling In JavaScript Functions from HTML Form To Validate User Entered Data
Calling In JavaScript Functions from HTML Form To Validate User Entered... and editing my html to call my functions to validate the user entered data...(zipCodeTextField.value) == true) { alert("Please enter a valid Zip Code Number
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
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
how to validate javascriptcode n i am attaching file give validations
how to validate javascriptcode n i am attaching file give validations  <%@page import="java.sql.SQLException"%> <%@page import...;} function setVisibility(id, visibility) { document.getElementById(id
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
how to validate javascriptcode n i am attaching file give validations
how to validate javascriptcode n i am attaching file give validations ...; function setVisibility(id, visibility) { document.getElementById(id).style.display...;/script> <script language="JavaScript"> function setVisibility(id
how to validate javascriptcode n i am attaching file give validations
how to validate javascriptcode n i am attaching file give validations ...; function setVisibility(id, visibility) { document.getElementById(id).style.display...;/script> <script language="JavaScript"> function setVisibility(id
how to validate javascriptcode n i am attaching file give validations
how to validate javascriptcode n i am attaching file give validations ...; function setVisibility(id, visibility) { document.getElementById(id).style.display...;/script> <script language="JavaScript"> function setVisibility(id
how to validate javascriptcode n i am attaching file give validations
how to validate javascriptcode n i am attaching file give validations ...; function setVisibility(id, visibility) { document.getElementById(id).style.display...;/script> <script language="JavaScript"> function setVisibility(id
how to validate javascriptcode n i am attaching file give validations
how to validate javascriptcode n i am attaching file give validations ...; function setVisibility(id, visibility) { document.getElementById(id).style.display...;/script> <script language="JavaScript"> function setVisibility(id
javascript regex validate Special character
javascript regex validate Special character   javascript regex validate Special character   <html> <head> <title>Zip...; function validate() { var zip = document.getElementById("zip").value
Session ID - Java Beginners
Session ID  Do we get new session id for a new domain after clicking..." + " Info TypeValue\n" + "\n" + " ID\n..." + "\n" + " Number of Previous Accesses\n
id
id  how to find date of birth and gender in id in html with the help of javascript
Validating Number Very Urgent - JSP-Servlet
: function Validate() { if(form.id.value=="") { alert("Employee ID cannot be null...; wat do u want to check? if u want to insert number only in the emp id...Validating Number Very Urgent  Respected Sir/Madam, I am
Validate textfield in Java Swing
Validate Jtextfield in Java Swing In this section,you will learn how to validate the textfield by allowing only numbers to enter. For this purpose, we have...()); con.add(new JLabel("Enter the number")); con.add(text); con.add(label
JavaScript validate select tag
JavaScript validate select tag In this tutorial, you will learn how to validate html select tag. Here, we have used two select tags to select numbers...; <script language = "Javascript"> function validate
validation of date,phone number,email - Java Beginners
validation of date,phone number,email  Sir how to validate date,phone number and email in java swings  Hi Friend, Try the following code...)"); t1=new JTextField(20); l2=new JLabel("Enter Phone Number
jQuery Convert string to number
jQuery Convert string to number In this tutorial , we will discuss about how to convert string (enter into input box) into number. In this example... it from input and also need to convert into number. We can do this by following
Tomahawk validateCreditCard tag
is used to validate a Credit Card Number entered by the user. If we want the user to enter a valid Credit Card Number then this validation...; Credit Card Number: <input id="_idJsp0:creditCardNumber" name="
JavaScript validation for decimal number
JavaScript validation for decimal number Here we are going to validate the text field value. For this, we have allowed the user to enter decimal number... it. If it contains the decimal sign (.) and it is a number then it will be declared as valid