Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1100
  • Last Modified:

Check if has only letters, numbers and underscore

What is the reg exp syntax for checking if a string has only letters, numbers and underscore in it?

thanks
0
blacklord
Asked:
blacklord
1 Solution
 
RoonaanCommented:
if(preg_match('/^\w+$/',$string)) {
  //string not empty and requested chars only
}

-r-
0
 
Richard QuadlingSenior Software DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now