South African Id Number Generator
Generate (Fake) South-African ID Numbers. Year of Birth. Month of Birth. Day of Birth. Show expert options. Hint: submit the form to get an ID number. More Information. See Wikipedia or this article. Read the code. Generate (Fake) South-African ID Numbers. Year of Birth. Month of Birth. Day of Birth. Ruby random South African ID number generator. GitHub Gist: instantly share code, notes, and snippets.
I've researched this but none of the code I use seems to work. South African ID numbers contain date of birth and gender. All I want is it to pull in that information and verify it when their ID number is entered into an input field, preferably in jQuery or javascript
Any help is appreciated,
Dawid
Archer
3 Answers
You could use Koenyn's regex validation, not so sure how a single-digit number (0-9?) from the input represents the gender but basing on this tool you provided and David Russell's Using Javascript to validate South African ID Numbers, here's an untested attempt:
UPDATE 1:After following this thread, What is a South African ID number made up of?, I updated my implementation to include the gender and citizenship tests.
UPDATE 2:Forgot to wrap the month number increment id_month + 1
within the date string fullDate
, updating solution with Dawid's fix.
HTML Markup:
Javascript:
DEMO: http://jsfiddle.net/chridam/VSKNx/
chridamchridamthis is the validation regex we us at our company:
as far as using regex, it's really simple http://www.w3schools.com/jsref/jsref_obj_regexp.asp
There is a jQuery plugin that you can use. Check it out at http://www.verifyid.co.za/jqueryid
6dev6il66dev6il6Washington Id Number Generator

Not the answer you're looking for? Browse other questions tagged javascriptjqueryvalidation or ask your own question.
def id_number(birthday, gender) |
gender = (0..4).to_a.sample if gender 'female' |
gender = (5..9).to_a.sample if gender 'male' |
random_sequence = rand.to_s[2..5] |
citizenship = 0 |
race = 8 |
id_number = [ |
birthday.gsub('-', ')[2..-1], |
gender, |
random_sequence, |
citizenship, |
race |
].join.split(').map(&:to_i) |
# Luhn digit |
luhn_total = 0 |
luhn_count = 0 |
id_number.each do d, x |
multiple = (luhn_count % 2) + 1 |
luhn_count += 1 |
temp = multiple * d |
luhn_total += (temp/10).floor + (temp % 10) |
end |
return id_number.push((luhn_total * 9) % 10).join |
end |
class ZaIdNumberValidator < ActiveModel::EachValidator |
def validate_each(record, attribute, value) |
if value.length != 13 |
record.errors[attribute] << (options[:message] 'Identification number is invalid') |
else |
id_number = value.to_s.split(').map(&:to_i) |
luhn_check = id_number.last |
luhn_total = 0 |
luhn_count = 0 |
id_number.take(12).each do d, x |
multiple = (luhn_count % 2) + 1 |
luhn_count += 1 |
temp = multiple * d |
luhn_total += (temp/10).floor + (temp % 10) |
end |
if luhn_check != (luhn_total * 9) % 10 |
record.errors[attribute] << (options[:message] 'Identification number is invalid') |
end |
end |
end |
end |
class Profile < ApplicationRecord |
validates :identification_number, |
presence: true, |
za_id_number: true |
end |