473,654 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting there with ereg() but..........

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) || (!ereg("^[a-zA-Z]+$",$fname)) ) {
$err1 = "Your first name was less than 2 characters and/or contains illegal
characters</br>";
$errors = 1;
}

Regards
Dynamo

Jul 17 '05 #1
3 1612
Dynamo wrote:
Can the following script be condensed into one ereg()
statement. If so how?
if ((strlen($fname ) < 2) || (!ereg("^[a-zA-Z]+$",$fname)) ) {
$err1 = "Your first name was less than 2 characters and/or contains illegal
characters</br>";
$errors = 1;
}


use the full quantifiers instead of the single-character ones

^[a-zA-Z]{2,}$
The most used quantifiers have a shorthand representation:
* ==> {0,}
+ ==> {1,}
? ==> {0,1}
Also consider switching to preg_*() functions. They're more powerful
then their ereg*() counterparts.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #2
Pedro Graca <he****@dodgeit .com> wrote:

Also consider switching to preg_*() functions. They're more powerful
then their ereg*() counterparts.


Plus preg_* comes with a pattern modififiers and syntax section in the
manual: http://nl2.php.net/manual/en/referen...ern.syntax.php
and http://nl2.php.net/manual/en/referen....modifiers.php

Well they might be a bit condensed but have some usefull links like:
http://www.regularexpressions.info/ and http://www.regexlib.com/

Jul 17 '05 #3
In article <sl************ *******@ID-203069.user.uni-berlin.de>, Pedro Graca
says...

Dynamo wrote:
Can the following script be condensed into one ereg()
statement. If so how?
if ((strlen($fname ) < 2) || (!ereg("^[a-zA-Z]+$",$fname)) ) {
$err1 = "Your first name was less than 2 characters and/or contains illegal
characters</br>";
$errors = 1;
}
use the full quantifiers instead of the single-character ones

^[a-zA-Z]{2,}$

[Snip]
Thanks. That did the trick
Also consider switching to preg_*() functions. They're more powerful
then their ereg*() counterparts.

[Snip]
This 50 year old has only just grasped the concept of reg expressions within
ereg() ;-) but thanks for the tip.

Regards
Dynamo

Jul 17 '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("^$", "[");
0
2013
by: erickrefener | last post by:
Hi, I use PHP (and PHP socket functions) to exchange very short XML documents between two Flash clients like this : <MESSAGE id="myid" text="mytext" /> I don't parse the XML document within PHP but send back the XML document made by the Flash client to another Flash client with a php socket and Flash parse it with its own XML parser ... In order to detect errors or non-XML data I do like this (in php):
0
2448
by: |-|erc | last post by:
<?php // Get the names and values for vars sent by index.lib.php3 if (isset($HTTP_GET_VARS)) { while(list($name,$value) = each($HTTP_GET_VARS)) { $$name = $value; }; };
0
2796
by: mcp6453 | last post by:
I am trying to use Jack's FormMail script (http://www.dtheatre.com/scripts/formmail). Since I'm brand new at PHP and not very good at HTML, I have an easy question, which I will narrow down. When the email arrives, it has this information: v_firstname: asdf v_lastname: asdf b_email: asdf@bellsouth.net v_phone: asdf v_cellphone: asdf
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
2
1214
by: Yannick Benoit | last post by:
Hi! I use this to find all links in a page : *(href)*=*(+) but recently i found out that it only works if links are setup this way: <a href = "... I would like to know if someone can help me find the proper expression which would work with <a href = "... <a href= "... <a href="... and <a href ="...
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 {
1
3187
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as follows: The code below is for the first page:session_start is in line 3 <link href="css/jobSheet.css" rel="stylesheet" type="text/css" /> session_start();
0
8290
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
8707
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
8482
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
8593
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...
0
7306
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...
0
4149
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...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1593
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.