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

Validating a Paragraphed String

1
Well I need a quick solution for checking if a string contains an email address or anything of the similar, example:

I allow user to type in their personal profile in a textarea and name it "profile"

so in php i will catch it in $profile but would want to check if there is an email value in it. If there is, an error will be trigered as this is not allowed.

Please help.

Thanks
May 19 '07 #1
2 1089
pbmods
5,821 Expert 4TB
Heya, basher. Welcome to TSDN!

You'll be wanting to use preg_match, and you'll probably like this article on searching for email addresses.
May 19 '07 #2
Odisey
14
Well I need a quick solution for checking if a string contains an email address or anything of the similar, example:

I allow user to type in their personal profile in a textarea and name it "profile"

so in php i will catch it in $profile but would want to check if there is an email value in it. If there is, an error will be trigered as this is not allowed.

Please help.

Thanks
Basher you want to use 'regular expressions'. Do a Google for recipe cut and paste scripts. Regular expressions in short are characters used - in this case - to constrain your data input to form. In other words, if a user does not input an email address as something@someplace.ext they will get the }else{ error you code.

Here is an example:

I am using the eregi() function as !eregi and the eregi_replace. What this does is first determines if the input is a formated email address. If not, the error. If so, it recodifies it as a link. YOU can adjust it of course. Learn more about Regular Expressions!

Expand|Select|Wrap|Line Numbers
  1.  
  2. //Check the mail address
  3.  
  4.    if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$',
  5.    stripslashes(trim($_POST['email'])))) {
  6.       $problem = TRUE;
  7.       $message .= '<p class="error">Please enter a valid email address.</p>';
  8.  
  9.     }  else  {
  10.  
  11.     $email = eregi_replace ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', '<a href="mailto:\\0">Email</a>', 
  12.     stripslashes(trim($_POST['email'])));
  13.  
  14. }    
  15.  
  16.  
  17.  
  18.  
Marc
May 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Brian Kedersha | last post by:
I found code for validating XML documents with the XML Schema cashed for rapid access. Example 3: Validating with XMLSchemaCache. ...
1
by: Christian | last post by:
Hi, I load an Xml-file "customers.xml" into a DataSet (works fine) but then how do I validate it against a schema (e.g. customers.xsd) ? my customers.xml: <?xml version="1.0"...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
6
by: Richard | last post by:
I'm validating a date and time string which must be EXACTLY of the format yy-mm-dd hh:mm:ss and extracting the six numeric values using sscanf. I'm using the format string "%2u-%2u-%2u...
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: 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
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...
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
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,...
0
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...
0
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...

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.