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

How to check if a character appears in a form variable?

Hi guys!

Can anyone tell me how you can perform validation on a string variable
in PHP so that you can check if a specific character is contained
within the string. The reason for this is i am trying to create a form
for a site i am making and i want to validate the user's input for the
email address field, by ensuring it contains the '@' character.

Cheers.

Sep 23 '05 #1
7 2640
monomaniac21 (ma********@msn.com) wrote:
: Hi guys!

: Can anyone tell me how you can perform validation on a string variable
: in PHP so that you can check if a specific character is contained
: within the string. The reason for this is i am trying to create a form
: for a site i am making and i want to validate the user's input for the
: email address field, by ensuring it contains the '@' character.

That is hardly a check to validate an email address!

However, one function that would help is strstr();

$at = strstr($claimed_email_address,"@");
if ($at == "")
{
echo "no @ found";
die ;
}

But there are dozens of other functions that would also help. The php
manual is available on line (google for it) look for string functions.
--

This programmer available for rent.
Sep 23 '05 #2
Instead, use preg_match to use Perl-style regular expressions.
It can check to see if it found a pattern.
For emails, use something like:

if( preg_match("/\w+@\w+\.\w+",$variable) )
{
do_whatever...;
}

which will check for the format ab*@abc.abc
Sep 23 '05 #3
Mazin07 wrote:
/\w+@\w+\.\w+


Ad hoc regular expressions to validate the syntax of e-mail addresses
are invariably both too loose and too strict. Too loose in that they
pass forms not allowed by RFC2822, too strict in that they reject
forms allowed by RFC2822. Even the Mail::RFC822::Address pattern
doesn't encompass the gamut of forms, but then it doesn't pretend to.

--
Jock
Sep 24 '05 #4
John Dunlop <us*********@john.dunlop.name> wrote:

Mazin07 wrote:
/\w+@\w+\.\w+


Ad hoc regular expressions to validate the syntax of e-mail addresses
are invariably both too loose and too strict. Too loose in that they
pass forms not allowed by RFC2822, too strict in that they reject
forms allowed by RFC2822. Even the Mail::RFC822::Address pattern
doesn't encompass the gamut of forms, but then it doesn't pretend to.


Jeffrey Friedl's book, "Mastering Regular Expressions" contains a complete
regular expression which matches all valid RFC 822 e-mail addresses. It is
more than 6,500 characters long.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 25 '05 #5
Tim Roberts wrote:
Jeffrey Friedl's book, "Mastering Regular Expressions" contains a complete
regular expression which matches all valid RFC 822 e-mail addresses. It is
more than 6,500 characters long.


Interesting. I don't have his book, but is that the pattern
Email::Valid uses?

http://search.cpan.org/src/MAURICE/E...-0.15/Valid.pm

--
Jock
Sep 25 '05 #6
John Dunlop <us*********@john.dunlop.name> wrote:
Tim Roberts wrote:
Jeffrey Friedl's book, "Mastering Regular Expressions" contains a complete
regular expression which matches all valid RFC 822 e-mail addresses. It is
more than 6,500 characters long.


Interesting. I don't have his book, but is that the pattern
Email::Valid uses?

http://search.cpan.org/src/MAURICE/E...-0.15/Valid.pm


That's the one. He credits Friedl in the code.

The Friedl book is actually quite good. Some people think the subject
could be adequately covered in a 3-page man page, but Friedl covers the
tricks, ins, and outs of many of the popular regular expression engines. I
recommend it.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 27 '05 #7
Tim Roberts wrote:
The Friedl book is actually quite good.
[...]
I recommend it.


It's on my wish list, Tim, right below 25-hour days.

--
Jock
Sep 30 '05 #8

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

Similar topics

7
by: Stefan Richter | last post by:
Hi, I am looking for a good function to check if a entered value is a money value - meaning it's a decimal with no more then 2 digits after the point. Thanks, Stefan
27
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
6
by: Joshua Weston | last post by:
I am new to C++ and I am very interested in becoming proficient. This post is two-fold. One, I am having problems with this small test program. It is meant to allow user input to control a "@"...
2
by: Mike | last post by:
I´ve got a number of SPAN elements named "mySpan1", "mySpan2", "mySpan3" etc, and want to set their "style.display" to "inline". This works (only needs to work on IE5.5+): for (var x = 1; x <...
3
by: Oliver Saunders | last post by:
is there anyway to check if a string could be used a variable name. So return false if the first character isn't a letter or if it contains spaces etc. I started writing a function that would do...
44
by: Kulgan | last post by:
Hi I am struggling to find definitive information on how IE 5.5, 6 and 7 handle character input (I am happy with the display of text). I have two main questions: 1. Does IE automaticall...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
5
by: Just D | last post by:
All, Any valuable idea about subj: "The '%' character, hexadecimal value 0x25" ? I tried to google, but nothing interesting was found. Is it IIS settings problem, user side problem or...
4
by: jameskuyper | last post by:
mkeles84 wrote: The other responses you've received have explained why 'name' needs to contain a Null-Terminated Character String (NTCS). However, it occurred to me that you might not be aware...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.