473,385 Members | 1,521 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() 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("location: ok.php");
}

function redirection() {
header("location: 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 2230
"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...checking 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
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...
18
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
6
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.