Advertisement
Johurt

[FNC] ItIsDate

Apr 16th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.63 KB | None | 0 0
  1. stock ItIsDate(string[]) // YYYY-MM-DD
  2. {
  3.     new len = strlen(string);
  4.     if(len != 10) return false;
  5.         for(new c; c < len; c++)
  6.     {
  7.         switch(c)
  8.                 {
  9.                     case 0..3, 5, 6, 8, 9:
  10.                         {
  11.                             if(string[c] > '9' || string[c] < '0') return false;
  12.                         }
  13.                         default:
  14.                         {
  15.                                 if(string[c] != '-') return false;
  16.                         }
  17.                 }
  18.         }
  19.         return true;
  20. }
  21. /* Use */
  22. printf("Date: %s", (ItIsDate("201a-01-20")) ? ("correct") : ("incorrect"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement