Page 1 of 1

Check for alpha characters

Posted: Wed Aug 16, 2006 11:52 am
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]

Posted: Wed Aug 16, 2006 11:57 am
by feyd
Save the regex for something else. Use the ctype functions.

Posted: Wed Aug 16, 2006 12:10 pm
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??

Posted: Wed Aug 16, 2006 12:12 pm
by Luke

Posted: Wed Aug 16, 2006 12:33 pm
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.

Posted: Wed Aug 16, 2006 12:34 pm
by Ambush Commander
I recommend using ctype_alpha(), it's faster than an ereg expression (and you ought to use the PCRE ones instead)

Posted: Wed Aug 16, 2006 3:01 pm
by mparker1113
Thank you for the answers. I got english by choosing the appropriiate dropdown list box choice for "View As" (i chose english :)

Re: Check for alpha characters

Posted: Wed Aug 16, 2006 5:45 pm
by bokehman
mparker1113 wrote:

Code: Select all

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