4
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by baig772
0

Dear subrata
i have already read this documentation.
still i am unable to write my own rule
:(

0

So only a-z, 0-9, - and _

if (preg_match('/[\w-]*/', $subject)) {
  # Successful match
} 
else {
  # Match attempt failed
}

Update: As minitauros states, use a + instead of a * if you want to match at least a single character.

Edited by pritaeas: n/a

1

Here's a good tutorial on regular expressions:

http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

In your case, I think you're looking for something like

preg_match('/^[0-9A-Za-z_\-]+$/', .....)

Which returns true if the input string contains nothing more than letters, numbers, underscores and dashes, or indeed, like pritaeas says

preg_match('/^[\w-]+$/', .....)

which is similair to that.

Edited by minitauros: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.