South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
function validateIdNumber($id) {
$match = preg_match ("!^(\d{2})(\d{2})(\d{2})\d{7}$!", $id, $matches);
if (!$match) {
return false;
}
list (, $year, $month, $day) = $matches;
/**
* Check that the date is valid
*/
if (!checkdate($month, $day, $year)) {
return false;
}
/**
* Now Check the control digit
*/
$d = -1;
$a = 0;
for($i = 0; $i < 6; $i++) {
$a += $id{2*$i};
}
$b = 0;
for($i = 0; $i < 6; $i++) {
$b = $b*10 + $id{2*$i+1};
}
$b *= 2;
$c = 0;
do {
$c += $b % 10;
$b = $b / 10;
} while($b > 0);
$c += $a;
$d = 10 - ($c % 10);
if($d == 10) $d = 0;
if ($id{strlen($id)-1} == $d) {
return true;
}
return false;
}
You can do that in JavaScript btw, very easy, Heita, I'll suggest you start getting your head stuck into JavaScript. It really is the future.
IMHO he would be better of using a static helper to do the validation using the format classes and then further reuse the helper as a EL function through the correct method signiture that automatically happens when one uses static helpers. My logic here is that the business layer would use the helper to ensure that ID numbers are valid as this seems business logic to me and I would throw an Runtime exception in such a case and clearly document that my business API must be called with valid ID numbers there is nothing to suggest that javascript is the future and there are already more favourable solutions like JSF and Swingwhich may be used with javawebstart.You can do that in JavaScript btw, very easy, Heita, I'll suggest you start getting your head stuck into JavaScript. It really is the future.
IMHO he would be better of using a static helper to do the validation using the format classes and then further reuse the helper as a EL function through the correct method signiture that automatically happens when one uses static helpers. My logic here is that the business layer would use the helper to ensure that ID numbers are valid as this seems business logic to me and I would throw an Runtime exception in such a case and clearly document that my business API must be called with valid ID numbers there is nothing to suggest that javascript is the future and there are already more favourable solutions like JSF and Swingwhich may be used with javawebstart.
Seeing all the nice jquery (and other library) stuff you can do, CSS and all the nifty grids you can do client side, why the hell would you NOT think that NOTHING suggests that javascript is the future. Stop wasting my time n00b
i love regex.
WTF? You smoking meth? Why would you want to over complicate a simple client side checking with an API and several layers of doo-hickeys which he barely understands to begin with?
JavaScript is the future, if you pull your head out of your ass you would see how much effort Google is putting into Chrome to make it the fastest JS renderer yet. Seeing all the nice jquery (and other library) stuff you can do, CSS and all the nifty grids you can do client side, why the hell would you NOT think that NOTHING suggests that javascript is the future. Stop wasting my time n00b
I think you are smoking meth. Fact: NOT EVERYONE knows CSS or even HTML. CSS + HTML are tools for web design and do not fall into the category of tools that are required to develop web applications anymore.
Can you explain why JSP would still be the choice if you already have a swing application?
Such a classic... How can ANYBODY forget it?lol, beat me to it![]()
Wow - I wholeheartedly agree. That is UTTER ignorance. The web is presented by HTML to every single client that accesses it.Sorry but I couldn't read past that point highlighted in bold. What utter idiocityI think you are smoking meth. Fact: NOT EVERYONE knows CSS or even HTML. CSS + HTML are tools for web design and do not fall into the category of tools that are required to develop web applications anymore.
AcidRaZor... ONE... Yucca... ZERO...
Round 2.... FIGHT!
![]()