Check for alpha characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mparker1113
Forum Commoner
Posts: 28
Joined: Wed Apr 05, 2006 9:39 am

Check for alpha characters

Post by mparker1113 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I only need to know if there are alpa characters in my string.

I have tried many combinations with regexperssions, preg_match, with no success. Anybody can do this?

Code: Select all

if(  !(preg_match("[:alpha"."]", "12345")))
echo ("are no characters<br>");
else 
   echo("charcters in string<br>");
   
   ?>

Code: Select all

if(  !(preg_match("[A-Z]", "12345")))
echo ("are no characters<br>");
else 
   echo("charcters in string<br>");
   
   ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Save the regex for something else. Use the ctype functions.
mparker1113
Forum Commoner
Posts: 28
Joined: Wed Apr 05, 2006 9:39 am

Post by mparker1113 »

I got it to work using ereg(). I am kind of upset that all of the pages I browse to in php.net aree in chineese or something. Anyone know the url to english to php.net??
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

mparker1113 wrote:I got it to work using ereg(). I am kind of upset that all of the pages I browse to in php.net aree in chineese or something. Anyone know the url to english to php.net??
This has happened to me recently a few times (Italian, French, Spanish). Not sure what is causing it, but if you go to http://www.php.net/manual/en/ it should take you to an English version of the manual an any of the PHP.net mirrorws.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I recommend using ctype_alpha(), it's faster than an ereg expression (and you ought to use the PCRE ones instead)
mparker1113
Forum Commoner
Posts: 28
Joined: Wed Apr 05, 2006 9:39 am

Post by mparker1113 »

Thank you for the answers. I got english by choosing the appropriiate dropdown list box choice for "View As" (i chose english :)
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Re: Check for alpha characters

Post by bokehman »

mparker1113 wrote:

Code: Select all

preg_match("[:alpha"."]", "12345")
[:alpha:] is a POSIX regex and has nothing to do with PCRE.
Post Reply