Skip to content

Instantly share code, notes, and snippets.

@devi
Created June 19, 2011 07:56
Show Gist options
  • Select an option

  • Save devi/1033909 to your computer and use it in GitHub Desktop.

Select an option

Save devi/1033909 to your computer and use it in GitHub Desktop.
slug/permalink validation
<?php
// lower alpha
// alnum followed by alnum or hyphen between alnum
function valid_slug1($value)
{
return (bool) preg_match('/^[a-z0-9]+(-[a-z0-9]+)*$/iD', (string) $value);
}
// alpha followed by alnum or hyphen between alnum
function valid_slug2($value)
{
return (bool) preg_match('/^[a-z]+(-?[a-z0-9]+)*$/iD', (string) $value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment