[PHP] Is there a special character I here?

2001-08-16 Thread Brandon Orther

Hello,
 
I am looking for a way to check a string if it has anything other than
Numbers or Letters.  Does anyone know how to do this?
Thank you,


Brandon Orther
WebIntellects Design/Development Manager
[EMAIL PROTECTED]
800-994-6364
www.webintellects.com
  
 



Re: [PHP] Is there a special character I here?

2001-08-16 Thread ERISEN, Mehmet Kamil

I use a javascript to do that for my forms:

if (window.RegExp) {
  var reg = new RegExp("^[_0-9a-z]*$","gi");
  if (!reg.test(f.elements['username'].value)) {
alert("Kullanici adi harf ve/veya rakamlardan
olusmalidir. Lutfen Duzeltiniz!");
f.elements['username'].focus();
return(false);
  }
}

I am sure you could write something similar with PHP.

--- Brandon Orther <[EMAIL PROTECTED]> wrote:
> Hello,
>  
> I am looking for a way to check a string if it has
> anything other than
> Numbers or Letters.  Does anyone know how to do this?
> Thank you,
> 
> 
> Brandon Orther
> WebIntellects Design/Development Manager
> [EMAIL PROTECTED]
> 800-994-6364
> www.webintellects.com
>   
>  
> 


=
Mehmet Erisen
http://www.erisen.com

__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Is there a special character I here? (RegularExpressions)

2001-08-16 Thread Guilherme Pinto

I am starting on php, coming from Perl. One thing I really like on the way
we can use regex in Perl is the shorthand:

\w --> [a-zA_Z0-9_]
\W --> [^a-zA_Z0-9_]
\d --> [0-9]
\D --> [^0-9]
\s --> white space characters
...

Is this shorthand handled in php?

Thanks,

Guilherme


On 8/16/01 5:17 PM, in article
Pine.BSF.4.10.10108170003580.9813-10@localhost, "Philip Olson"
<[EMAIL PROTECTED]> wrote:

> It's probably a good idea to learn a bit about regular
> expressions.
> 
> In short, PHP gives us two types of regular expressions
> to play with, POSIX and PCRE.  For more information :
> 
> PCRE   : http://php.net/manual/en/ref.pcre.php
> POSIX  : http://php.net/manual/en/ref.regex.php
> 
> The following is an example rich tutorial :
> 
> http://www.phpbuilder.org/columns/dario19990616.php3
> 
> It uses ereg, which is POSIX :
> 
> ereg() : http://php.net/manual/en/function.ereg.php
> 
> Your question is "How can I make sure a string contains
> ONLY alpha-numeric characters?"  That could look like :
> 
> $string = 'examPle123';
> 
> if (eregi("^[a-z0-9]+$",$string)) {
>  
>   echo 'String is alpha-numeric';
> } else {
>   echo 'String is NOT alpha-numeric';
> }
> 
> Which in english says :
> 
> if the string :
>- begins with // ^
>- contains one to an unlimited number of  // +
>- ends with   // $
> the following characters :
>a-z  // all lowercase letters
>A-Z  // comes from i in eregi (case insensitive)
>0-9  // all numbers
> then this is TRUE.
> 
> Let's say we wanted to make sure the length was between
> 3-11 characters, tinkering with the regex the following
> works :
> 
> if (eregi("^[a-z0-9]{3,11}$",$string)) {
> 
>   echo 'Is alpha-numeric and 3-11 characters in length';
> } else {
>   echo 'Is NOT alpha-numeric and/or 3-11 characters in length';
> }
> 
> Allowing spaces in $string is easy as : [a-z0-9 ]
> 
> Also, some good variable and string functions exist :
> 
> variables : http://php.net/manual/en/ref.var.php
> strings   : http://php.net/manual/en/ref.strings.php
> 
> Regards,
> Philip Olson
> 
> 
> On Thu, 16 Aug 2001, Brandon Orther wrote:
> 
>> Hello,
>>  
>> I am looking for a way to check a string if it has anything other than
>> Numbers or Letters.  Does anyone know how to do this?
>> Thank you,
>> 
>> 
>> Brandon Orther
>> WebIntellects Design/Development Manager
>> [EMAIL PROTECTED]
>> 800-994-6364
>> www.webintellects.com
>> 
>>  
>> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Is there a special character I here? (Regular Expressions)

2001-08-16 Thread Philip Olson

It's probably a good idea to learn a bit about regular 
expressions.
 
In short, PHP gives us two types of regular expressions 
to play with, POSIX and PCRE.  For more information :
 
  PCRE   : http://php.net/manual/en/ref.pcre.php
  POSIX  : http://php.net/manual/en/ref.regex.php
 
The following is an example rich tutorial :
 
  http://www.phpbuilder.org/columns/dario19990616.php3
 
It uses ereg, which is POSIX :
 
  ereg() : http://php.net/manual/en/function.ereg.php
 
Your question is "How can I make sure a string contains
ONLY alpha-numeric characters?"  That could look like :
 
  $string = 'examPle123';

  if (eregi("^[a-z0-9]+$",$string)) {
   
echo 'String is alpha-numeric';
  } else {
echo 'String is NOT alpha-numeric';
  }

 Which in english says :
 
  if the string :
 - begins with // ^
 - contains one to an unlimited number of  // +
 - ends with   // $
  the following characters :
 a-z  // all lowercase letters
 A-Z  // comes from i in eregi (case insensitive)
 0-9  // all numbers
  then this is TRUE.

Let's say we wanted to make sure the length was between 
3-11 characters, tinkering with the regex the following 
works :
 
  if (eregi("^[a-z0-9]{3,11}$",$string)) {
 
echo 'Is alpha-numeric and 3-11 characters in length';
  } else {
echo 'Is NOT alpha-numeric and/or 3-11 characters in length';
  }

Allowing spaces in $string is easy as : [a-z0-9 ]
 
Also, some good variable and string functions exist :
 
  variables : http://php.net/manual/en/ref.var.php
  strings   : http://php.net/manual/en/ref.strings.php

Regards,
Philip Olson


On Thu, 16 Aug 2001, Brandon Orther wrote:

> Hello,
>  
> I am looking for a way to check a string if it has anything other than
> Numbers or Letters.  Does anyone know how to do this?
> Thank you,
> 
> 
> Brandon Orther
> WebIntellects Design/Development Manager
> [EMAIL PROTECTED]
> 800-994-6364
> www.webintellects.com
>   
>  
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Is there a special character I here? (Regular Expressions)

2001-08-16 Thread Rasmus Lerdorf

> I am starting on php, coming from Perl. One thing I really like on the way
> we can use regex in Perl is the shorthand:
>
> \w --> [a-zA_Z0-9_]
> \W --> [^a-zA_Z0-9_]
> \d --> [0-9]
> \D --> [^0-9]
> \s --> white space characters
> ...
>
> Is this shorthand handled in php?

Sure, all the preg* functions take Perl-style regular expressions like
that.  Read the manual: http://php.net/pcre

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]