yuhsing

Untitled

Feb 17th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2. function isValidIC($ic)
  3. {
  4. $pattern = '/^\d{6}-\d{2}-\d{4}$/';
  5. if (preg_match($pattern, $ic))
  6. {
  7. $year = substr($ic, 0, 2);
  8. $month = substr($ic, 2, 2);
  9. $day = substr($ic, 4, 2);
  10. if (checkdate($month, $day, $year))
  11. {
  12. return true;
  13. }
  14. }
  15. return false;
  16. }
  17. ?>
  18. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  19. <html>
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  22. <title>P1Q10</title>
  23. <link rel="stylesheet" type="text/css" href="style.css" />
  24. </head>
  25. <body>
  26. <?php
  27. $s1 = 'INVALID-IC-NUM';
  28. $s2 = '999999-01-1234';
  29. $s3 = '900231-01-1234';
  30. $s4 = '900214-01-1234';
  31.  
  32. echo '<pre>';
  33. echo $s1. ' = ' . (isValidIC($s1) ? 'Valid' : 'Invalid') . "\n";
  34. echo $s2. ' = ' . (isValidIC($s2) ? 'Valid' : 'Invalid') . "\n";
  35. echo $s3. ' = ' . (isValidIC($s3) ? 'Valid' : 'Invalid') . "\n";
  36. echo $s4. ' = ' . (isValidIC($s4) ? 'Valid' : 'Invalid') . "\n";
  37. echo '</pre>';
  38. ?>
  39.  
  40. <p>
  41. [ <a href="index.php">Back</a> ]
  42. </p>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment