NC wrote:[color=blue]
> Fernando Rodríguez wrote:[color=green]
> >
> > How can I know if a string only has alfanumeric chars?[/color]
>
> By feeding it to is_numeric():[/color]
Oops, sorry, didn't read the question carefully...
"Alphanumer ic" is a context-dependent concept. For example, ASCII 247
is not alphanumeric in Latin-1, but it does in fact correspond to a
letter in Cyrillic-1251...
What you may want to do is to define "alphanumer ic" more precisely and
then look at each character in the sting to see if it meets your
definition of "alphanumer ic".
"Colin McKinnon"
<colin.thisisno tmysurname@ntlw orld.deletemeun lessURaBot.com> wrote in
message news:74NAf.6252 0$Dg6.12645@new sfe3-gui.ntli.net...[color=blue]
> Fernando Rodredguez wrote:
>[color=green]
>>
>> Hi,
>>
>> How can I know if a string only has alfanumeric chars?
>>
>> Thanks[/color]
>
> Use a regex.
>
> C.[/color]
<usenet@isotope REEMOOVEmedia.c om> wrote in message
news:98jsu1pkpu hasfudb7iksdp7h 75jbc3sns@4ax.c om...[color=blue]
> On Thu, 9 Feb 2006 14:02:04 -0800, "Jim Michaels"
> <jmichae3@nospa m.yahoo.com>
> wrote:[color=green]
>>"Colin McKinnon"
>><colin.thisis notmysurname@nt lworld.deleteme unlessURaBot.co m> wrote in
>>message news:74NAf.6252 0$Dg6.12645@new sfe3-gui.ntli.net...[color=darkred]
>>> Fernando Rodredguez wrote:
>>>
>>>> How can I know if a string only has alfanumeric chars?
>>>>
>>>
>>> Use a regex.
>>>
>>> C.[/color]
>>
>>give him an example!
>>
>>preg_match( '/^[\w\d]$/', $string);
>>[/color]
>
> Or use the built-in function.
> www.php.net/ctype_alpha[/color]
that's half of it. I think you meant www.php.net/ctype_alnum
admittedly, this looks much easier. :-)
On Thu, 9 Feb 2006 14:02:04 -0800, "Jim Michaels" <jmichae3@nospa m.yahoo.com>
wrote:
[color=blue][color=green][color=darkred]
>>> How can I know if a string only has alfanumeric chars?[/color][/color]
>
>give him an example!
>
>preg_match('/^[\w\d]$/', $string);[/color]
\w includes more than alphanumeric (it includes underscore), but includes all
of \d.
Alternatives could be:
/^[a-zA-Z\d]+$/
... or even ...
/^[^\W_]+$/
... for ASCII definitions of "alphanumer ic", anyway.
Comment