Connecting Tech Pros Worldwide Forums | Help | Site Map

Ereg question

bonehead
Guest
 
Posts: n/a
#1: Jul 17 '05
Greetings,

I'd like to add somee error handling to a password field: if the
password is fewer than 5 characters or greater than 15 characters I'd
like to trap it. Special characters such as ^ and ~ will be allowed, but
spaces will not be allowed.

Can someone suggest and ereg expression that will help with this? Also,
does php have a length function similar to vb's len(mystring)?

Chung Leong
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Ereg question


Yup, regular expression is the perfect tool for this task. Try this:

echo preg_match('|^\\w{5,15}$|', $password) ? "Good" : "Bad";

Uzytkownik "bonehead" <sendmenospam@here.org> napisal w wiadomosci
news:3FD20296.1070008@here.org...[color=blue]
> Greetings,
>
> I'd like to add somee error handling to a password field: if the
> password is fewer than 5 characters or greater than 15 characters I'd
> like to trap it. Special characters such as ^ and ~ will be allowed, but
> spaces will not be allowed.
>
> Can someone suggest and ereg expression that will help with this? Also,
> does php have a length function similar to vb's len(mystring)?
>[/color]


Tormod Fjeldskår
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Ereg question


bonehead wrote:
[color=blue]
> Also, does php have a length function similar to vb's len(mystring)?[/color]

Sure: $length = strlen($mystring);
<URL: http://no2.php.net/manual/en/function.strlen.php>

--
Tormod Fjeldskår
tormod@fritidsproblemer.no
http://tormod.fritidsproblemer.no/
bonehead
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Ereg question


Chung I must say you've been very very helpful. Sure hope you're getting
paid enough. And are you actually fluent in Polish?

Chung Leong wrote:[color=blue]
> Yup, regular expression is the perfect tool for this task. Try this:
>
> echo preg_match('|^\\w{5,15}$|', $password) ? "Good" : "Bad";
>
> Uzytkownik "bonehead" <sendmenospam@here.org> napisal w wiadomosci
> news:3FD20296.1070008@here.org...
>[color=green]
>>Greetings,
>>
>>I'd like to add somee error handling to a password field: if the
>>password is fewer than 5 characters or greater than 15 characters I'd
>>like to trap it. Special characters such as ^ and ~ will be allowed, but
>>spaces will not be allowed.
>>
>>Can someone suggest and ereg expression that will help with this? Also,
>>does php have a length function similar to vb's len(mystring)?[/color][/color]

Chung Leong
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Ereg question


I get paid well enough for someone who studies Polish :-)

Uzytkownik "bonehead" <sendmenospam@here.org> napisal w wiadomosci
news:3FD220FE.30500@here.org...[color=blue]
> Chung I must say you've been very very helpful. Sure hope you're getting
> paid enough. And are you actually fluent in Polish?
>
> Chung Leong wrote:[color=green]
> > Yup, regular expression is the perfect tool for this task. Try this:
> >
> > echo preg_match('|^\\w{5,15}$|', $password) ? "Good" : "Bad";
> >
> > Uzytkownik "bonehead" <sendmenospam@here.org> napisal w wiadomosci
> > news:3FD20296.1070008@here.org...
> >[color=darkred]
> >>Greetings,
> >>
> >>I'd like to add somee error handling to a password field: if the
> >>password is fewer than 5 characters or greater than 15 characters I'd
> >>like to trap it. Special characters such as ^ and ~ will be allowed, but
> >>spaces will not be allowed.
> >>
> >>Can someone suggest and ereg expression that will help with this? Also,
> >>does php have a length function similar to vb's len(mystring)?[/color][/color]
>[/color]


Shawn Wilson
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Ereg question


bonehead wrote:[color=blue]
>
> Greetings,
>
> I'd like to add somee error handling to a password field: if the
> password is fewer than 5 characters or greater than 15 characters I'd
> like to trap it. Special characters such as ^ and ~ will be allowed, but
> spaces will not be allowed.
>
> Can someone suggest and ereg expression that will help with this? Also,
> does php have a length function similar to vb's len(mystring)?[/color]

The preg functions are usually faster than the ereg. And strlen() will give you
the string length.

Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
Closed Thread


Similar PHP bytes