By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,044 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,044 IT Pros & Developers. It's quick & easy.

Ereg question

P: n/a
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)?

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Yup, regular expression is the perfect tool for this task. Try this:

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

Uzytkownik "bonehead" <se**********@here.org> napisal w wiadomosci
news:3F**************@here.org...
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)?

Jul 17 '05 #2

P: n/a
bonehead wrote:
Also, does php have a length function similar to vb's len(mystring)?


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

--
Tormod Fjeldskår
to****@fritidsproblemer.no
http://tormod.fritidsproblemer.no/
Jul 17 '05 #3

P: n/a
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:
Yup, regular expression is the perfect tool for this task. Try this:

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

Uzytkownik "bonehead" <se**********@here.org> napisal w wiadomosci
news:3F**************@here.org...
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)?


Jul 17 '05 #4

P: n/a
I get paid well enough for someone who studies Polish :-)

Uzytkownik "bonehead" <se**********@here.org> napisal w wiadomosci
news:3F************@here.org...
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:
Yup, regular expression is the perfect tool for this task. Try this:

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

Uzytkownik "bonehead" <se**********@here.org> napisal w wiadomosci
news:3F**************@here.org...
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)?

Jul 17 '05 #5

P: n/a
bonehead wrote:

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)?


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

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.