473,657 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ereg() dilemma

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("[a-z][A-Z][0-9]", $Pword) && ereg("[a-z][A-Z][0-9]", $User)) {
redirection2();
}
else {
redirection();
}

and that also goes to the wrong.php page (which I put in a following
else), that's why I assumed try checking that it equals 1, but still no
good. HELP ME PLEASE!!

<?php
function redirection2() {
header("locatio n: ok.php");
}

function redirection() {
header("locatio n: wrong.html");
}

$User = $_POST["Username"];
$Pword = $_POST["Password"];

if(ereg("([a-z][A-Z][0-9])", $User, $Pword) == 1) {
redirection2();
}
else {
redirection();
}
?>

Oct 9 '05 #1
3 2242
"ra************ @gmail.com" wrote:
... 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("[a-z][A-Z][0-9]", $Pword) && ereg("[a-z][A-Z][0-9]", $User)) {
redirection2();
}
else {
redirection();
}


You need to learn a bit more about regular expressions.

The expression "[a-z][A-Z][0-9]" matches a single lowercase letter, followed
by a single uppercase letter, followed by a single digit. Any string
containing this combination will pass your test (try "-+= xY2 &/;", for
example -- the sequence "xY2" in the middle is enough to pass your test).

In this case, something like "^[a-zA-Z0-9]+$" would probably work better,
although I don't think it's wise to restrict passwords to alphanumeric
characters only. Why not allow other symbols like /, _, !, @, #, $, %, ^, &,
* as well? And don't names sometimes contain spaces or hyphens?

You can also define minimum and maximum lengths for these strings by
replacing "+" with something like "{4,20}". I'll leave you to figure out how
this all works. The documentation is perfectly clear:

<http://php.net/manual/en/reference.pcre. pattern.syntax. php>

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Oct 9 '05 #2
Thank you thank you! :) fixed! I didn't realise the [] and order
made a difference...ch ecking out the link you provided. i agree with
your points about spaces, underscores etc, but that unfortunately isnt
up to me in this instance but ill work out how to use them too. ;)

thanks again :)

Oct 9 '05 #3
> Thank you thank you! :) fixed!

I know exactly what it feels when you get help from *kind hearted*
newsgroups guys. Great expression, indeed!

I still remember my older days. Still getting a big deal help.

--
Raqueeb Hassan
Bangladesh

Oct 9 '05 #4

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
1613
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))) {
18
2015
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
6
4093
by: millw0rm | last post by:
why i m getting error here??? Warning: ereg(): REG_BADBR code: if(!ereg("^(.){15,400}$",$string)) { $errormsg = "- Must be more then 15 Characters & less then 400 Characters"; }
0
8302
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
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
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...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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
5630
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
4150
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...
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.