Created
October 24, 2012 07:52
-
-
Save mikkohei13/3944652 to your computer and use it in GitHub Desktop.
Regular expression validator: returns TRUE if subject does not fully match pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isInvalid($subject, $pattern) | |
{ | |
preg_match($pattern, $subject, $matches); | |
if ($matches[0] == $subject) | |
{ | |
return FALSE; | |
} | |
else | |
{ | |
return TRUE; | |
} | |
} | |
/* | |
Examples: | |
Year between 2000-2019: | |
if (isInvalid($_GET['year'], "/[2][0][0-1][0-9]/")) | |
{ | |
exit("Virhe vuosiluvussa. Korjaa ja yritä uudelleen"); | |
} | |
YKJ Grid: | |
if (isInvalid($_GET['key'], "/[6-7][0-9][0-9][:][3][0-9][0-9]/")) | |
{ | |
exit("Virhe koordinaattiruudussa. Korjaa ja yritä uudelleen"); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment