473,804 Members | 3,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_MET HOD=="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 2717
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...@g mail.com" <lepage.di...@g mail.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_MET HOD=="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...@g mail.com" <lepage.di...@g mail.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_MET HOD=="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**********@gm ail.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_MET HOD=="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...@elis anet.fiwrote:
lepage.di...@gm ail.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_MET HOD=="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...@elis anet.fiwrote:
lepage.di...@gm ail.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_MET HOD=="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**********@gm ail.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_ME THOD=="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*******@attgl obal.net
=============== ===
Mar 3 '07 #7
Hello,

on 02/28/2007 12:57 PM le**********@gm ail.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_MET HOD=="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
8297
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 with form elements that turn out to be arrays that have to be compared with one another! I have one form element, languages, a checkbox group. Beside each checkbox is a dropdown, proficiency (which will become proficiency alongside languages)....
4
9985
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 performing the validation check on the values that were entered into the form, I simply repost the form to perform the PHP validation. If any of the values that have been entered into the form are incorrect, I display a warning message on the screen...
4
2657
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 script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the validation procedure.
16
2255
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 individual fields, such as an "Email Validation Script" or a "Phone Validation Script". Is it ok to put all these scripts on page as they are or should they be joined in some way together to be one script? I'm a total JavaScript newbie and am completely...
9
4184
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
27
4764
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
11
3004
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
10
5731
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 form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to "<>"IsNull" so that when the user tries to tab through/click out of a required area without entering...
5
3227
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 javascript method will do the form validation for each field one by one. For each field, an XMLHttpRequst will be made to a PHP file and get the return, either set an error field (<span>'s innerHTML) or leave it empty. Then I'll check the error field...
7
3624
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
9706
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
9584
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,...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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...
0
9160
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
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
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
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
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.