Return to Snippet

Revision: 21189
at December 6, 2009 12:25 by rupakdhiman


Initial Code
/^[a-z0-9-]+$/

To use this expression follow the code below.

//Save the expression in a variable.
$correct_slug = "/^[a-z0-9-]+$/";

//some input from a user through a text field or from a server.
$user_input = $_REQUEST['sometext'];

//match the two input's and save it in a variable.
slug_match = preg_match($correct_slug, $user_input);

//Condition goes here.
if(slug_match){
  echo "Correct Input";
}
else{
   echo "Incorrect Input";
}

Initial URL


Initial Description
This is a regular expression to match a Slug. Slug that contains hyphens ("-").

Initial Title
Regular expression to match a Slug

Initial Tags


Initial Language
PHP