We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2896
    • 70 Posts
    Hi,

    I would like to create some control/validation for a field that contains the Belgian National number. This national number (rijksregisternummer) consist of 11 digits: the first 6 are the date of birth in reverse order, then a space and 3 digits, a space and then 2 control check digits

    Like in:
    740723 198 06

    What would be the best way to setup and validate this field in eform?
    (i’ve read the doc about REGEX and so on, but I’m a newbie at this point sad ) So any help much appreciated

    thx
      • 16278
      • 928 Posts
      Try this:
      eform="RRN::0:Invalid national number:#REGEX /^\d{6} \d{3} \d{2}$/"

      Rules:
      /....../ mark beginning and end of regex string
      ^indicates first character in input string, and $ the last
      \d stands for any decimal digit
      {n} requires the preceding character or expression exactly n times
      and the spaces are spaces.
      laugh
      KP
        • 30223
        • 1,010 Posts
        Quote from: kp52 at Mar 16, 2009, 11:04 AM

        Try this:
        eform="RRN::0:Invalid national number:#REGEX /^\d{6} \d{3} \d{2}$/"

        Rules:
        /....../ mark beginning and end of regex string
        ^indicates first character in input string, and $ the last
        \d stands for any decimal digit
        {n} requires the preceding character or expression exactly n times
        and the spaces are spaces.
        laugh
        KP

        This will certainly validate any numbers that follow the exact pattern of xxxxxx xxx xx but it will by no means guarantee that this is a valid Belgian National Number. It is quite easy to make a validation function which checks for a valid "Rijksregisternummer"

        Firstly here’s the function:
        <?php
        if(!function_exists(validateRijksNummer)){
        	function validateRijksNummer($v){
        		$v = preg_replace('/\D/','',$v);	//remove any non digit characters
        		$check = substr($v,-2);
        		$principal = substr($v,0,-2);
        		//check for birthdays before 2000
        		if( 97-($principal%97)!=$check){
        			//if this fails test for birthdays in 2000 and up
        			$principal = '2'.$principal;
        			if(97-($principal%97)!=$check) return false;
        		}
        		return true;
        	}
        }
        ?>
        

        Here’s how it works. The Rijksregisternummer (RN) can be checked by subtracting the modulus 97 of the first nine digits form 97 for birthdates before 2000 and for birthdates since 2000 by prefixing the nine digit number with ’2’ and using the same modulus method.

        So although you may write and expect the value to be in the format "xxxxxx xxx xx" to check the number you actually only want the digits. The functions uses a regular expression to remove all non-digit characters and then splits the value into the principal number and the check number. The function next checks according to the rule above for a birth date before 2000 and if this fails checks against a birthdate since 2000. If both fail the function returns false.

        To use this function first create a new snippet (let’s call it ’validateFunctions’) and paste the code above. Then include this snippet in yor document just before yor eForm call:

        [[validateFunctions]]
        [!eForm? .......!]
        


        Now in your form set the eform attribute as follows:
        eform="RRN::0:Ongeldig Rijksregistratienummer:#FUNCTION validateRijksNummer"


        Good luck with it.
          • 2896
          • 70 Posts
          I’ve been "out" for a while, thanks for the solution/reply!
          i will give it a try and get back to you

            • 2896
            • 70 Posts
            Hi TobyL,

            This worked like a charm!! Thx a lot