south african id number validation c#
C#
//Validate ID Number
//JQuery
<script>
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
$('#idCheck').click(function () {
// first clear any left over error messages
$('#error p').remove();
// store the error div, to save typing
var error = $('#error');
var idNumber = $('#check').val();
// assume everything is correct and if it later turns out not to be, just set this to false
var correct = true;
//Ref: http://www.sadev.co.za/content/what-south-african-id-number-made
// SA ID Number have to be 13 digits, so check the length
if (idNumber.length != 13 || !isNumber(idNumber))
{
error.append('<p>ID number does not appear to be authentic</p>');
correct = false;
}
// get first 6 digits as a valid date
var tempDate = new Date(idNumber.substring(0, 2), idNumber.substring(2, 4) - 1, idNumber.substring(4, 6));
var id_date = tempDate.getDate();
var id_month = tempDate.getMonth();
var id_year = tempDate.getFullYear();
var fullDate = id_date + "-" + id_month + 1 + "-" + id_year;
if (!((tempDate.getYear() == idNumber.substring(0, 2)) && (id_month == idNumber.substring(2, 4) - 1) && (id_date == idNumber.substring(4, 6)))) {
//error.append('<p>ID number does not appear to be authentic - date part not valid</p>');
correct = false;
}
// get the gender
var genderCode = idNumber.substring(6, 10);
var gender = parseInt(genderCode) < 5000 ? "Female" : "Male";
// get country ID for citzenship
var citzenship = parseInt(idNumber.substring(10, 11)) == 0 ? "Yes" : "No";
// apply Luhn formula for check-digits
var tempTotal = 0;
var checkSum = 0;
var multiplier = 1;
for (var i = 0; i < 13; ++i) {
tempTotal = parseInt(idNumber.charAt(i)) * multiplier;
if (tempTotal > 9) {
tempTotal = parseInt(tempTotal.toString().charAt(0)) + parseInt(tempTotal.toString().charAt(1));
}
checkSum = checkSum + tempTotal;
multiplier = (multiplier % 2 == 0) ? 1 : 2;
}
if ((checkSum % 10) != 0) {
//error.append('<p>ID number does not appear to be authentic - check digit is not valid</p>');
correct = false;
};
// if no error found, hide the error message
if (correct) {
error.css('display', 'none');
// clear the result div
$('#result').empty();
// and put together a result message
$('#result').append('<p>South African ID Number: ' + idNumber + '</p><p>Birth Date: ' + fullDate + '</p><p>Gender: ' + gender + '</p><p>SA Citizen: ' + citzenship + '</p>');
}
// otherwise, show the error
else {
error.css('display', 'block');
}
});
</script>
//HTML
<div class="form-group">
<label>ID Number:<b style="color:red; ">*</b></label>
<div class="input-group mb-3">
<input type="text" name="ID" id="check" class="form-control" required >
<div class="input-group-append">
<button class="btn btn-primary" type="button" id="idCheck">Validate</button>
</div>
</div>
<div id="result" style="width:100%; background-color:rgba(58, 114, 59, 0.48); padding:5px; border-radius:5px; color:white; "></div>
<div id="error" style="width:100%; background-color:rgba(219, 23, 23, 0.48); padding:5px; border-radius:5px; color:white; "></div>
</div>
Also in C#:
- Title
- c# switct case
- Category
- C#
- Title
- lazy loading c#
- Category
- C#
- Title
- how to create a list in c# unity
- Category
- C#
- Title
- unity ui change sprite
- Category
- C#
- Title
- how to track a branch on github
- Category
- C#
- Title
- show double in textbox c#
- Category
- C#
- Title
- application variable in asp.net core
- Category
- C#
- Title
- unity t-flip flop
- Category
- C#
- Title
- unity quaternion
- Category
- C#
- Title
- how to deactivate objects through scripts in unity
- Category
- C#
- Title
- scaffold-dbcontext sql server
- Category
- C#
- Title
- isdaylightsavingtime in c#
- Category
- C#
- Title
- get waht is differnt between two arrays c#
- Category
- C#
- Title
- convert string to decimal c#
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- convert string to boolean c#
- Category
- C#
- Title
- c# replace string case insensitive
- Category
- C#
- Title
- get enum by index c#
- Category
- C#
- Title
- unity how to change the text on a button
- Category
- C#
- Title
- what is the namespace for textmesh pro
- Category
- C#
- Title
- percentage in c#
- Category
- C#
- Title
- how to join array indexes with comma in c#
- Category
- C#
- Title
- unity if gameobject exists
- Category
- C#
- Title
- uinput dialog uwp c#
- Category
- C#
- Title
- application isPlaying unity
- Category
- C#
- Title
- c# substring from index to end
- Category
- C#
- Title
- c# convert to nullable datetime
- Category
- C#
- Title
- unity add component
- Category
- C#
- Title
- asign only common fields in c# object
- Category
- C#
- Title
- unity rotate around point
- Category
- C#
- Title
- c# escape characters
- Category
- C#
- Title
- c# make request to rest api
- Category
- C#
- Title
- unity round
- Category
- C#
- Title
- c# how to have a multiline console.writeline
- Category
- C#
- Title
- c# list to string join
- Category
- C#
- Title
- list with two values c#
- Category
- C#
- Title
- mailkit send attachment
- Category
- C#
- Title
- razor: show editable list
- Category
- C#
- Title
- C# .net core convert string to enum
- Category
- C#
- Title
- c# how to delete a file
- Category
- C#
- Title
- list contains type c#
- Category
- C#
- Title
- how to populate listbox using list<t> c#
- Category
- C#
- Title
- zip file ignoring directory starting with dot
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- c# quaternion eular calculator
- Category
- C#
- Title
- add row and columns to grid wpf in code
- Category
- C#
- Title
- unity c# run a command then wait
- Category
- C#
- Title
- to list c#
- Category
- C#
- Title
- c# storing value in session
- Category
- C#
- Title
- same click event diffrenet buttonms c#
- Category
- C#
- Title
- c# list length
- Category
- C#
- Title
- c# list get sublist
- Category
- C#
- Title
- unity array c#
- Category
- C#
- Title
- download file from url asp net web api c#
- Category
- C#
- Title
- phone
- Category
- C#
- Title
- how to use variables in c#
- Category
- C#
- Title
- transform.translate unity
- Category
- C#
- Title
- c# catch two exceptions in one block
- Category
- C#
- Title
- vb.net check if datatable has rows
- Category
- C#
- Title
- c# get index of item in list
- Category
- C#
- Title
- .net core copy file in folder to root
- Category
- C#
- Title
- c# retrieve files in folder
- Category
- C#
- Title
- c# class declaration
- Category
- C#
- Title
- c# list remove item based on property duplicate
- Category
- C#
- Title
- unity3d get component
- Category
- C#
- Title
- unity check if gameobject is active
- Category
- C#
- Title
- convert string to double c#
- Category
- C#
- Title
- get random point within radius
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- 2d character controller unity
- Category
- C#
- Title
- How to solve error in ExecuteNonQuery() in asp.net
- Category
- C#
- Title
- c# bitmap to picturebox
- Category
- C#
- Title
- strtorime online
- Category
- C#
- Title
- how to make a datatable in c#
- Category
- C#
- Title
- c# length of array
- Category
- C#
- Title
- c# linq select specific columns
- Category
- C#
- Title
- call a function c#
- Category
- C#
- Title
- what is a return statement C#
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- c# ienumerable to list
- Category
- C#
- Title
- c# object clone
- Category
- C#
- Title
- unity jump
- Category
- C#
- Title
- unity randomly generated numbers c#
- Category
- C#
- Title
- degree between two points latitude longitude c#
- Category
- C#
- Title
- c# null conditional operator if statement
- Category
- C#
- Title
- cannot convert string to generic type c#
- Category
- C#
- Title
- get number of sundays in a month c#
- Category
- C#
- Title
- set rotation to velocity unity
- Category
- C#
- Title
- how to allow user import image c#
- Category
- C#
- Title
- c# distinct array of objects by values
- Category
- C#
- Title
- button commandfield commandargument pass textbox
- Category
- C#
- Title
- length of a string c#
- Category
- C#
- Title
- dictionary c#
- Category
- C#
- Title
- c# System.Resources.MissingManifestResourceException error
- Category
- C#
- Title
- use newtonsoft json to clone object
- Category
- C#
- Title
- c# resize bitmap
- Category
- C#
- Title
- c# directories loop
- Category
- C#
- Title
- Generate Genealogy view in mvc C# using Google Organizational Chart
- Category
- C#
- Title
- divide string in chunks c#
- Category
- C#
- Title
- moq raise event
- Category
- C#