?
Solved

Regex to find all non-alphanumeric except dash (-)

Posted on 2006-05-28
2
Medium Priority
?
3,089 Views
Last Modified: 2009-12-16
I'm useless at regular expressions and can't for the life of me find what I need to enter as my pattern in preg_match_all to find all non-alphanumeric characters except dashes (-). Alphanumeric characters can be upper or lower case but no spaces or anything else aside from dashes can be allowed.

For anyone who has their head wrapped around regex I hope this is an easy one! Many thanks.
0
Comment
Question by:wjdashwood
2 Comments
 
LVL 5

Accepted Solution

by:
aminerd earned 2000 total points
ID: 16779885

if (preg_match('/[^a-zA-Z0-9\-]/', $string))
{
    die('Invalid string!');
}

Enjoy.
0
 

Author Comment

by:wjdashwood
ID: 16779904
Thank you aminerd, now how come I just can't get my head around creating that by myself?!?  :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question