473,653 Members | 2,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Uzytkownik "bonehead" <se**********@h ere.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($mystrin g);
<URL: http://no2.php.net/manual/en/function.strlen .php>

--
Tormod Fjeldskår
to****@fritidsp roblemer.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**********@h ere.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**********@h ere.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**********@h ere.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***@glassgian t.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
2345
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
2411
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 (ereg("^$patt$",$matricola))
3
20982
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 input a regular expression, enabling the administrator to ensure a file upload matches a certain pattern. For instance, supplying the string '.exe$|.com$|.bat$|.zip$|.doc$'
2
4452
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
2409
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 missed. I want to find a value for key1 in string: key1=>value_of key1key2=>other_valuekey3=>value and I use an ereg pattern
3
1612
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 create my own regular expressions. (Heaven help us!) So I have started with some pretty basic stuff but would like some advice on the following. Can the following script be condensed into one ereg() statement. If so how? if ((strlen($fname) < 2)...
3
1600
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 while it successfully refuses any non-digit, it still lets any number of digits through. Any suggestions? if ((ereg("({1,2})", $people))&&(ereg("({1,2})", $rooms))) {
3
2242
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 the result of this is that it only ever goes to wrong!!! please tell me why! I cant figure it out and feel so stupid! I even tried with : if(ereg("", $Pword) && ereg("", $User)) { redirection2(); } else {
18
2015
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8704
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.