473,396 Members | 1,590 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,396 software developers and data experts.

Question about Regular Expressions

Hello All,

I am fairly new to using regular expressions and I am totally lost as
to why the following code won't work. Basically, all I need to do is
find out if the text entered into a text field is an email address or
not (I'm searching for the "@" symbol. If it is, I want to display it
as a mailto link. If it's not, then I will just display the text. But
when I run the code it tries to create links out of EVERYTHING, not
just email addresses. Can someone point me in the right direction?
Thanks in advance and here's the code:

<?php
$contact = stripslashes($_POST['contact']);
$check = preg_match("/@/", $contact);
if($check){
...create the link here
}
else{
...just display the information
}
?>

Thanks!
Anthony

Sep 1 '05 #1
4 1069
*** Anthony P. wrote/escribió (1 Sep 2005 14:02:51 -0700):
I am fairly new to using regular expressions and I am totally lost as
to why the following code won't work. Basically, all I need to do is
find out if the text entered into a text field is an email address or
not (I'm searching for the "@" symbol. If it is, I want to display it
as a mailto link. If it's not, then I will just display the text. But
when I run the code it tries to create links out of EVERYTHING, not
just email addresses.


The code you paste just tests whether there's a @ symbol. How do you
extract the address itself?
BTW, this page may help:

http://www.merlyn.demon.co.uk/js-valid.htm#VEmA

It's for JavaScript but regex syntax is almost the same.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Sep 2 '05 #2
Actually, I don't really *need* to extract the email address. I just
need to know IF it's an email address.

So, from what you're saying, it sounds like I'm doing the test
correctly. But, for some reason, it's still failing. Any ideas why?

Thanks!
Anthony

Sep 2 '05 #3
BTW, thanks for the link!

Sep 2 '05 #4
*** Anthony P. wrote/escribió (2 Sep 2005 11:59:34 -0700):
So, from what you're saying, it sounds like I'm doing the test
correctly. But, for some reason, it's still failing. Any ideas why?


Your error must be somewhere else then. Your code works fine for me.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Sep 5 '05 #5

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Dwayne Epps | last post by:
I've created a function that checks form fields that only will have letters. This is the script: <script type="text/javascript" language="javascript"> function validateString(field, msg, min,...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
4
by: OneSolution | last post by:
I am trying to write a regular expression that will match all the exceptions generated in my application log file. I have done it as such: \bjava\.\w+\.\w+Exception: However, there are two...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
12
by: =?Utf-8?B?SlA=?= | last post by:
I am a newbie to regular expressions and want to extract a number from the end of a string. The string would have these formats: image/4567 image/45678 image/456789 I would also want to...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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,...
0
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...
0
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...
0
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,...

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.