/ Published in: PHP
This is a regular expression to match a Slug. Slug that contains hyphens ("-").
- 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.
- echo "Correct Input";
- echo "Incorrect Input";
You need to login to post a comment.