Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-05-2009, 12:43 PM Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I tried using an ereg on a textbox once sent through the post. For example it always goes to false no matter what the input was, even if it was in the correct state.

Is my ereg expression ok, for letters and caps, numbers and spaces and 5-20 chars

PHP Code:
if(ereg("^[a-zA-Z0-9][:space:]{5,20}$"$_POST['stadium_name']))
{
return 
"True";
} else {
return 
"False";

evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 02-05-2009, 12:48 PM Re: Ereg
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
My guess:
PHP Code:
if(ereg("^[a-zA-Z0-9\040]{5,20}$"$_POST['stadium_name'])) 
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 12:48 PM Re: Ereg
Average Talker

Posts: 28
Name: Fred Van Andel
Trades: 0
Your RE is looking for a single letter or number followed by 5 to 20 spaces.

You probably want "^[a-zA-Z0-9]{5,20}[:space:]$"

fava
__________________

Please login or register to view this content. Registration is FREE
tracks and graphs host reviews.

Last edited by fava; 02-05-2009 at 12:49 PM..
fava is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 12:55 PM Re: Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
nope still doesn't work!

Letters in any order and caps!
Numbers in any order!
Allow spaces any where!
Must be between 5 - 20 chars!

Any ideas on a ereg???
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-05-2009, 01:01 PM Re: Ereg
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Ehm.
Mine works.
I tested it.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 01:19 PM Re: Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
oh i didnt spot urs! i used fava!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-05-2009, 01:21 PM Re: Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
your one still doesnt work!

It doesnt except Redbridge Park
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-05-2009, 01:57 PM Re: Ereg
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Uhm.
That's really weird, because it does accept it for me. :P
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 02:01 PM Re: Ereg
Average Talker

Posts: 28
Name: Fred Van Andel
Trades: 0
If you want spaces in the name then you need:

"^[a-zA-Z0-9 \t]{5,20}$"

Note: php4 ereg does not support [:space:]
__________________

Please login or register to view this content. Registration is FREE
tracks and graphs host reviews.
fava is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 03:04 PM Re: Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
cheers im using php5
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-05-2009, 03:06 PM Re: Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Still doesn't except Redbridge Park
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-05-2009, 03:20 PM Re: Ereg
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Mine does, I'm sure of it.
I've tested in PHP in both ereg and preg_match, and I've also tested it in various RegEx programs.
They all match Redbridge Park with the pattern I provided.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 03:23 PM Re: Ereg
Average Talker

Posts: 28
Name: Fred Van Andel
Trades: 0
Interesting, it should work.

Do you have a trailing newline in the string that is causing the match to fail?

There is a simple interactive regex matcher at http://www.gskinner.com/RegExr/

Try that ind let me know what it shows.
__________________

Please login or register to view this content. Registration is FREE
tracks and graphs host reviews.
fava is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 03:34 PM Re: Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
the [a-zA-Z0-9 \t] bit works but it doesnt work once i put the {5-20} bit in!

How do i make it set the min limit of 5 chars and the max limit of 20 chars?

Last edited by evans123; 02-05-2009 at 03:40 PM..
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-05-2009, 03:49 PM Re: Ereg
Average Talker

Posts: 28
Name: Fred Van Andel
Trades: 0
Thats odd, in the regex matcher that I gave a link for it does match. The only thing I can think of is that there is newline or some other whitespace at the end of the string.

Does ^[a-zA-Z0-9 \t]{5,20}$ work?
Does ^[a-zA-Z0-9 \t]{5,20} work?
Does ^[a-zA-Z0-9 \t]$ work?
Does ^[a-zA-Z0-9 \t]{5,20}\n$ work?
Does ^[a-zA-Z0-9 \t]{5,20}.$ work?

fava
__________________

Please login or register to view this content. Registration is FREE
tracks and graphs host reviews.
fava is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 03:54 PM Re: Ereg
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
It's {5,20} not {5-20}.
Maybe that's your mistake, because I'm sure mine works as well.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-05-2009, 04:15 PM Re: Ereg
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Nah still doesn't work with the , instead of -

PHP Code:
// Change Stadium Name
if(isset($_POST['change_stadium']))
{
if(
$_POST['stadium_name'] != "" && $_POST['stadium_name'] != $_SESSION['stadium_name'])
{
if(
$_SESSION['change_stadium'] == 1)
{
if(
ereg("^[a-zA-Z0-9 \t]{5,20}$"$_POST['stadium_name']))  
{
$num_rows mysql_num_rows(mysql_query("SELECT * FROM `manager__teams` WHERE `stadium_name` = '" $_POST['stadium_name'] . "'"));
if(
$num_rows == 0)
{
echo 
expense($_SESSION['team_id'], "other"50000);
mysql_query("UPDATE `manager__teams` SET `stadium_name` = '$stadium_name', `change_stadium` = '1' WHERE `id` = '" $_SESSION['team_id'] . "'");
$stadium $_SESSION['stadium_name'];
$_SESSION['stadium_name'] = $stadium_name;
$note "Your stadium is now known as $stadium_name.";
} else {
$note "That stadium name is already taken please choose another name.";
}
} else {
$note "You have already changed your stadium name this season. Please wait until next season to change it again.";
}
} else {
$note "Stadium names can only contain letters, numbers and spaces and must be 5-20 characters long.";
}
}

evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Reply     « Reply to Ereg
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.02396 seconds with 12 queries