Solved

Check if has only letters, numbers and underscore

Posted on 2006-07-14
2
1,067 Views
Last Modified: 2008-09-09
What is the reg exp syntax for checking if a string has only letters, numbers and underscore in it?

thanks
0
Comment
Question by:blacklord
2 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 17106294
if(preg_match('/^\w+$/',$string)) {
  //string not empty and requested chars only
}

-r-
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 17106730
NOTE!

A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word". The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place. For example, in the "fr" (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 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