473,395 Members | 1,658 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.

form validation

Hello

I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.

1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc

Another thing is I don't want people to be able to leave any of the
fields blank.

Where does the validation code go?

After this statement?

if($REQUEST_METHOD=="POST") or before?

I have tried a few things, but I am not sure what most people use, any
help would be appreciated.

Have a wonderful day

Diane

Feb 28 '07 #1
7 2686
Hi,

Here's one function to check an email address:

http://www.ilovejackdaniels.com/php/...ss-validation/

For phone, you could do:

if (!preg_match('/^[2-9]\d{2}-\d{4}$/', $email)) {
// Bad phone
}

For address, you could do:

$addr = preg_replace('#[^[[:print:]]]|[/\\\\]#', '', $addr);

You can check that each item is filled-in like so:

$errors = array();
if (trim($_POST['name']) == '') {
$errors[] = 'Name is missing.';
}
if (trim($_POST['addr']) == '') {
$errors[] = 'Address is missing.';
}
foreach ($errors as $err) {
echo "<span style=\"color: red;\">$err</span><br>";
}
On Feb 28, 10:57 am, "lepage.di...@gmail.com" <lepage.di...@gmail.com>
wrote:
Hello

I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.

1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc

Another thing is I don't want people to be able to leave any of the
fields blank.

Where does the validation code go?

After this statement?

if($REQUEST_METHOD=="POST") or before?

I have tried a few things, but I am not sure what most people use, any
help would be appreciated.

Have a wonderful day

Diane

On Feb 28, 10:57 am, "lepage.di...@gmail.com" <lepage.di...@gmail.com>
wrote:
Hello

I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.

1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc

Another thing is I don't want people to be able to leave any of the
fields blank.

Where does the validation code go?

After this statement?

if($REQUEST_METHOD=="POST") or before?

I have tried a few things, but I am not sure what most people use, any
help would be appreciated.

Have a wonderful day

Diane

Feb 28 '07 #2
..oO(petersprc)
>Here's one function to check an email address:

http://www.ilovejackdaniels.com/php/...ss-validation/
I still doubt that this will match all valid addresses. The RFC is way
too complex to be handled with a simple regular expression. Compare the
address from the site above with this one:

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

I would just check that there's an "@" char with something before it,
something after it and no line breaks. That's it. Just because a mail
address looks valid doesn't mean that it really exists, so why bother?
Just send out a mail and either it will reach its destination or not.

Micha
Feb 28 '07 #3
le**********@gmail.com formulated on keskiviikko :
Hello

I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.

1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc

Another thing is I don't want people to be able to leave any of the
fields blank.

Where does the validation code go?

After this statement?

if($REQUEST_METHOD=="POST") or before?

I have tried a few things, but I am not sure what most people use, any
help would be appreciated.

Have a wonderful day

Diane
Hi, you should check these:
http://www.php.net/manual/en/ref.filter.php,
http://phpro.org/tutorials/Filtering-Data-with-PHP.html and
http://devzone.zend.com/node/view/id/1113.

-Lurius
Mar 1 '07 #4
On Mar 1, 2:40 pm, Lurius <romu.k...@elisanet.fiwrote:
lepage.di...@gmail.com formulated on keskiviikko :
Hello
I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.
1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc
Another thing is I don't want people to be able to leave any of the
fields blank.
Where does the validation code go?
After this statement?
if($REQUEST_METHOD=="POST") or before?
I have tried a few things, but I am not sure what most people use, any
help would be appreciated.
Have a wonderful day
Diane

Hi, you should check these:http://www.php.net/manual/en/ref.fil...e/view/id/1113.

-Lurius
So much restriction as old thing now.
For address king of thing just check those invalid char that can harm
your system.

Mar 3 '07 #5
On Mar 1, 2:40 pm, Lurius <romu.k...@elisanet.fiwrote:
lepage.di...@gmail.com formulated on keskiviikko :
Hello
I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.
1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc
Another thing is I don't want people to be able to leave any of the
fields blank.
Where does the validation code go?
After this statement?
if($REQUEST_METHOD=="POST") or before?
I have tried a few things, but I am not sure what most people use, any
help would be appreciated.
Have a wonderful day
Diane

Hi, you should check these:http://www.php.net/manual/en/ref.fil...e/view/id/1113.

-Lurius
So much restriction as old thing now.
For address kind of things just check those invalid chars that can
harm your system.

Mar 3 '07 #6
Lurius wrote:
le**********@gmail.com formulated on keskiviikko :
>Hello

I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.

1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc

Another thing is I don't want people to be able to leave any of the
fields blank.

Where does the validation code go?

After this statement?

if($REQUEST_METHOD=="POST") or before?

I have tried a few things, but I am not sure what most people use, any
help would be appreciated.

Have a wonderful day

Diane

Hi, you should check these: http://www.php.net/manual/en/ref.filter.php,
http://phpro.org/tutorials/Filtering-Data-with-PHP.html and
http://devzone.zend.com/node/view/id/1113.

-Lurius

Don't bother. While the idea is good, this is one of the worst
interfaces ever added to PhP.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 3 '07 #7
Hello,

on 02/28/2007 12:57 PM le**********@gmail.com said the following:
Hello

I am a newbie to PHP. Please bear with me. I need to validate the
following fields using php.

1. email (needs to be just one e-mail address, and take out stuff like
bcc or anything that would be used for e-mail injection vulnerability)
2. Phone number (has to be in the format 555-5555)
3. Phone number area code (has to be limited to 3 characters)
4. Address has to be stripped of all illegal characters like slashes,
special characters etc

Another thing is I don't want people to be able to leave any of the
fields blank.

Where does the validation code go?

After this statement?

if($REQUEST_METHOD=="POST") or before?

I have tried a few things, but I am not sure what most people use, any
help would be appreciated.
Take a look at this forms generation and validation. It does all that
you ask without need to learn special javascript:

http://www.phpclasses.org/formsgeneration

Here is a generic example in action:

http://www.meta-language.net/forms-examples.html
--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Mar 4 '07 #8

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

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.