Archive for September, 2010
Functie ter controle van Belgisch Rijksregisternummer in C#
0Onderstaande functie kan gebruikt worden om Belgische rijksregisternummers te valideren.
De samenstelling van een rijksregisternummer wordt op deze wiki-pagina uitgelegd: http://nl.wikipedia.org/wiki/Rijksregisternummer
De code geeft een string terug. Deze bevat “M” of “F” naargelang het om een geldig mannelijk of vrouwelijk rijksregisternummer gaat, of een omschrijving van gevonden fouten indien ongeldig.
De functie laat als input ook spaties, punten (.) en dashes (-) toe om een nummer met deze karakters ook te kunnen controleren.
De namespaces System.Text.RegularExpressions en System.Globalization dienen gerefenceerd te worden.
using System.Text.RegularExpressions;
using System.Globalization;
public string CheckRRNumberValidity(string input)
{
if (input != null)
{
string message = "";
Regex nonAllowedCharacters = new Regex(@"[^0-9. -]");
Regex nonNumeric = new Regex(@"[^0-9]");
string rrnumber = input;
if (nonAllowedCharacters.IsMatch(rrnumber))
return "Non allowed character";
else
{
//STRIP THE NUMBER FROM ALL NON NUMERIC CHARS
rrnumber = nonNumeric.Replace(rrnumber, "");
//LENGTH MUST BE 11 DIGITS
if (rrnumber.Length != 11)
return "Length != 11";
else
{
try
{
bool birthDateOK = false;
bool counterOK = false;
bool controlOK = false;
bool born2kOrLater = false;
string gender = "(unknown)";
//FIRST 6 DIGITS ARE BIRTHDATE IN FORMAT YYMMDD
string birthDatePart = rrnumber.Substring(0, 6);
//NEXT 3 ARE COUNTER
string counterPart = rrnumber.Substring(6, 3);
//LAST 2 ARE CONTROLNUMBER
string controlPart = rrnumber.Substring(9, 2);
/* 1. CONTROL NUMBER CHECKING */
/******************************/
//CALCULATE CONTROLNUMER (= MOD 97 OF FIRST 9 DIGITS)
int calculatedControl = 97 - (int)(Int64.Parse(birthDatePart + counterPart) % 97);
if (calculatedControl != Int32.Parse(controlPart))
{
/* IF THE CALCULATED CONTROL PART IS DIFFERENT THAN THE ONE IN THE INPUTSTRING
* ADD A "2" IN FRONT OF THE BIRTHDATEPART AND RECALCULATE. THIS WAS INTRODUCED TO
* ALLOW BIRTHDATES OF YEAR 2000 AND LATER
*/
calculatedControl = 97 - (int)(Int64.Parse("2" + birthDatePart + counterPart) % 97);
if (calculatedControl != Int32.Parse(controlPart))
{
/* THE CALCULATION STILL DOESN'T MATCH THE CONTROLNUMER, SO THIS IS AN INVALID
* REGISTRY NUMBER
*/
controlOK = false;
}
else
{
born2kOrLater = true;
controlOK = true;
}
}
else
controlOK = true;
/* 2. BIRTHDATE CHECKING */
/*************************/
string d = birthDatePart;
//BUILD THE BIRTHDATE TO CHECK
if (born2kOrLater == true)
d = "20" + birthDatePart;
else
d = "19" + birthDatePart;
//END BUILD
string format = "yyyyMMdd";
DateTime birthDate;
birthDateOK = DateTime.TryParseExact(d, format, CultureInfo.CurrentCulture, DateTimeStyles.None, out birthDate);
Console.WriteLine(birthDate.ToString("dd/MM/yyyy"));
/* 3. COUNTER CHECKING */
/***********************/
/* COUNTERPART MUST BE BETWEEN 001 AND 997
* EVEN FOR FEMALE
* ODD FOR MALE
*/
int counter = Int32.Parse(counterPart);
if (counter < 1 || counter > 997)
counterOK = false;
else if (counter % 2 == 0) //EVEN
{
counterOK = true;
gender = "F"; //FEMALE
}
else
{
counterOK = true;
gender = "M"; //MALE
}
/* 4. RETURN GENDER OR MESSAGE */
/*******************************/
if (!birthDateOK)
message += "Invalid birthdate;";
if (!counterOK)
message += "Invalid counter;";
if (!controlOK)
message += "Invalid control number;";
if (!message.Equals("")) //THERE ARE ERRORS
{
if (message.EndsWith(";"))
message = message.Substring(0, message.Length - 1);
return message;
}
else //IF GETTING HERE, NUMBER SHOULD BE CORRECT AND GENDER FILLED IN
return gender;
}
catch (Exception ex)
{
return "Exception";
}
}
}
}
else
{
return "isnull";
}
}
Friendly Go-Karting race @ Berck-Sur-Mer, France
0On September 12th, 2010, I took part in the 8th annual go-karting trophy of Berck-Sur-Mer, France.
It’s a coastal city in the French department of the Nord-Pas-de-Calais.
Each year, they transform part of the seaside-walk into a racing track with help of strawbales, where the participants then unleash their mean-machines. It’s very bumpy and wild, especially on these karts with no suspension. It wears you out pretty dang well after a full day of racing.
I started out good, grabbed pole position in my category, and won the first of 3 races. Was in the lead in the second one but then unfortunately I hit a swerving backmarker while trying to overtake him. It bent my rear axle and had to retire. I later found out I had a 4 second lead over the second placed driver at the time of the collision. I didn’t know that, as it is very difficult to look behind you at this track. If I had known it, I probably would have been more cautious while lapping other guys.
Anyway we managed to hammer the axle almost straight again in the pits, and I started the final race in 10th spot. I was able to quickly make up some positions, partly by overtaking, partly due to some guys in front of me crashing. By lap 5 of 17 I was in 3rd, and had a 10 lap long battle with the second placed guy until I finally was able to overtake him when he was a little held up by a backmarker. But with 2 laps to go, the leader was long gone and I could do nothing more than settle for second.
Considering the crash I had in the pre-final, 2nd place still is a good result, although I probably would have won it if I hadn’t had those problems…. but that’s racing.
Here are some of the best pictures of the day:


















