Skip to content

Instantly share code, notes, and snippets.

@mikkohei13
Created October 24, 2012 07:52
Show Gist options
  • Save mikkohei13/3944652 to your computer and use it in GitHub Desktop.
Save mikkohei13/3944652 to your computer and use it in GitHub Desktop.
Regular expression validator: returns TRUE if subject does not fully match pattern
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