473,796 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding @ in a string, and other items

Ok - I want to check a string for @ in it (Im checking to see if a string
that should contain an email holds a @ )

How would I go about this? preg_match? ereg? strstr?Examples ?

Also - how would I find any non alpha numeric characters in a string so I
can give the user an error message. I dont want any characters besides
alpha-numeric in the strings.
Jul 17 '05 #1
11 2208
It's easiest to use regexp to deal with this sort of thing.
preg_match('/^[\w\.]+@\w+\.\w+/', $address) should do the trick.

Uzytkownik "Picture Dots" <we*******@brim stonedragons.co m> napisal w
wiadomosci news:HQ******** *********@fe1.c olumbus.rr.com. ..
Ok - I want to check a string for @ in it (Im checking to see if a string
that should contain an email holds a @ )

How would I go about this? preg_match? ereg? strstr?Examples ?

Also - how would I find any non alpha numeric characters in a string so I
can give the user an error message. I dont want any characters besides
alpha-numeric in the strings.

Jul 17 '05 #2
I noticed that Message-ID: <wo************ ********@comcas t.com> from
Chung Leong contained the following:
It's easiest to use regexp to deal with this sort of thing.
preg_match('/^[\w\.]+@\w+\.\w+/', $address) should do the trick.


Reg exp and easy in the same sentence?

if (!strpos($email ,"@"))
{
print "try again, email addresses must contain \"@\"";
}
else{
print "That's a fine email address!";
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
Your solution does not provide any check other than checking for existance
of @
The regexp does :)

Mich

"Geoff Berrow" <bl******@ckdog .co.uk> wrote in message
news:gi******** *************** *********@4ax.c om...
I noticed that Message-ID: <wo************ ********@comcas t.com> from
Chung Leong contained the following:
It's easiest to use regexp to deal with this sort of thing.
preg_match('/^[\w\.]+@\w+\.\w+/', $address) should do the trick.


Reg exp and easy in the same sentence?

if (!strpos($email ,"@"))
{
print "try again, email addresses must contain \"@\"";
}
else{
print "That's a fine email address!";
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Jul 17 '05 #4
Michel wrote upsidedown:
"Geoff Berrow" <bl******@ckdog .co.uk> wrote in message
news:gi******** *************** *********@4ax.c om...
if (!strpos($email ,"@")) [...]
Your solution does not provide any check other than checking for existance
of @


One of the queries was how to go about checking a string contained
"@". Using regular expression functions for that alone would be
inefficient.
The regexp does :)


Indeed. But it doesn't answer the other query (how to detect non-
alphanumeric characters in a string). So why use it?

I suspect Picture Dots is trying to confirm the validity of email
addresses, but neither the Subject line nor the body of the original
article says so. The pattern in question is insufficient for
checking email address syntax.

--
Jock
Jul 17 '05 #5
I noticed that Message-ID: <c0*********@ne ws.cistron.nl> from Michel
contained the following:
Your solution does not provide any check other than checking for existance
of @
The regexp does :)


I know. But I think such checks are pointless anyway.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6
More or less. Mistyping a email address that's synatically correct is far
more likely than enter a invalid character. Doing a MX lookup might be more
worthwhile than trying to write a regexp that validates RFC822 conformance.

Uzytkownik "Geoff Berrow" <bl******@ckdog .co.uk> napisal w wiadomosci
news:bk******** *************** *********@4ax.c om...
I noticed that Message-ID: <c0*********@ne ws.cistron.nl> from Michel
contained the following:
Your solution does not provide any check other than checking for existanceof @
The regexp does :)


I know. But I think such checks are pointless anyway.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Jul 17 '05 #7
"Chung Leong" <ch***********@ hotmail.com> wrote in message news:<hs******* *************@c omcast.com>...
More or less. Mistyping a email address that's synatically correct is far
more likely than enter a invalid character. Doing a MX lookup might be more
worthwhile than trying to write a regexp that validates RFC822 conformance.

Uzytkownik "Geoff Berrow" <bl******@ckdog .co.uk> napisal w wiadomosci
news:bk******** *************** *********@4ax.c om...
I noticed that Message-ID: <c0*********@ne ws.cistron.nl> from Michel
contained the following:
Your solution does not provide any check other than checking for existanceof @
The regexp does :)


I know. But I think such checks are pointless anyway.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/


You can find a regular expression to validate email-address here:

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

Try using this if it worth using for your email-validation :)

--
Thanks,
Rahul Anand
Jul 17 '05 #8
Rahul Anand wrote:
You can find a regular expression to validate email-address here:

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
This is a Perl module which validates email addresses against the
syntax of RFC822 (obsoleted by RFC2822); the pattern itself will not
match all valid email addresses, despite its complexity.
Try using this if it worth using for your email-validation :)


Validating the syntax of an email address and finding it exists is
not proof of it being in use. If you'd like to know that what a user
entered is really her email address, then a confirmation mail is the
best way, as both the CGI FAQ and the Mail::RFC822::A ddress
documentation recommend.

--
Jock
Jul 17 '05 #9
John Dunlop <jo*********@jo hndunlop.info> wrote in message news:<MP******* *************** **@News.Individ ual.NET>...
Validating the syntax of an email address and finding it exists is
not proof of it being in use. If you'd like to know that what a user
entered is really her email address, then a confirmation mail is the
best way, as both the CGI FAQ and the Mail::RFC822::A ddress
documentation recommend.

Yes, I agree. Best way is to send a mail with confirmation URL or some
confirmation code. Only after actual validation you can be sure that
the request is authentic.

--
Cheers,
Rahul Anand
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2062
by: Mr. B | last post by:
I'm writing an app where I'm trying to look for and List all specific file 'types' found. So I point to a specific start top level Folder... and I want to drill down through ALL sub folders to find file types (using File Extenion). All found DWG files are listed in "lbDwgList" Listbox. I can get the top level and the 'immediate' level below the top level... but I can't figure out how to keep going down X levels (ie: All sub-levels). ...
6
7577
by: Tarun | last post by:
Hi All, I need to find a particular substring in a binary string(some text appended & prepended to binary data). I cant use strstr since it terminates on receiving '\0'which can be there in binary data also I cant use memmem. Is there any other available function to do this. Regards Tarun
10
1758
by: tshad | last post by:
I have a Datagrid with a column: <asp:HyperLinkColumn DataTextField="JobTitle" DataNavigateUrlField="PositionID" DataNavigateUrlFormatString="AddNewPositions.aspx?PositionID={0}" HeaderText="Job Title" Visible="True" SortExpression="JobTitle"/>
12
5420
by: Mike Smith | last post by:
Hey anyone knows how to find an item in a list view based on text ? Cant seem to get the IndexOf method working. would the LVM_FINDITEM method using SendMessage API work in .Net ?
0
1251
by: Sridhar | last post by:
Hi, I have a datagrid which contains some bound columns, some template columns. The template columns contain text box in one column, Hyperlink column in other column, dropdownlist in another column etc. Now I would like to read the values in each of these columns. Inorder to read those I am doing string text1 = CType(datagrid1.Items(0).cells(0).controls(0), TextBox).Text string text2 = CType(datagrid1.Items(0).cells(1).controls(0),...
2
2853
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. The SELECT query is built as follows: $itemtype = stripslashes(trim($_POST));
1
1689
by: Simon Forman | last post by:
I've got a function that I'd like to improve. It takes a list of lists and a "target" element, and it returns the set of the items in the lists that appear either before or after the target item. (Actually, it's a generator, and I use the set class outside of it to collect the unique items, but you get the idea. ;-) ) data = , , ,
7
9083
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've tried several different approaches for finding the placeholder: This: MyControl = this.FindControl("$form$tabs_repeater$PlaceHolder1"); Produces this error: Object reference not set to an instance of an object.
4
1730
by: Cralis | last post by:
I have a Combo box, populated from a List<Objects>. The Object has a .name, and .id property. The combo box has been populated with these using DisplayMember and ValueMember. When I load the screen, and am editing an item, the combo must go to the correct 'Manufacturer' that the main screen wants to see. This is based on a Model object I have. The model has a manufacturer. So, I populate the combo with the possible Manufacturers, but...
0
9685
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
9535
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
10465
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
10242
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
10021
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
7558
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
5453
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
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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.