473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Ereg question

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
5 2872
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stefan Gangefors | last post by:
I'm trying to figure out what I'm doing wrong when using ereg(). This is my regexp: ereg("^]$", "]"); and that does'n work, but this does: ereg("^$", "[");
9
by: Fiore Alessandro | last post by:
Hi all I've installed Apache 2.0.48 and PHP 4.3.4 on a workstation running Linux, RedHat 9.0. Let's consider the following piece of code: $patt = "{3}/{6}"; if...
3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
2
by: pomho | last post by:
Hi all, Even having read the PHP Manual, I can't understand the difference between the ereg function and the preg_match... Could anyone help ? thx in advance, --
3
by: Rafal Zak | last post by:
I have a little problem with ereg (eregi) in PHP - in some cases it behaves differently than I expect and I don`t know if my expectations are strange or there is any "syntax subtlety" I have...
3
by: Dynamo | last post by:
Hi, Thanks to all who replied to original posting.As a direct result of now gaining a better understanding of regular expressions, instead of trying to use other peoples scripts I am now trying to...
3
by: news | last post by:
I'm trying to make sure a form has only one or two digits in either of two fields. I looked at php.net and http://www.regular-expressions.info/reference.html and this is what I put together, but...
3
by: rachellara1979 | last post by:
Hi, new to PHP and to this group, so very sorry if this is simple or has been covered before. Basically want to check that a user and password (entered in a previous page) only has characters but...
18
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.