Re: form validation



Hi,

Here's one function to check an email address:

http://www.ilovejackdaniels.com/php/email-address-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...@xxxxxxxxx" <lepage.di...@xxxxxxxxx>
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...@xxxxxxxxx" <lepage.di...@xxxxxxxxx>
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


.



Relevant Pages

  • Re: Trim Help
    ... country has a trunk prefix which is dialed just before the area code for a ... phone number begins with the International Prefix of the country of origin, ... Then there's the bit about alpha characters. ...
    (microsoft.public.sqlserver.programming)
  • Re: Changing area code in contact data
    ... leading characters and will be followed by 3 other numbers and then followed ... Before they can be used of course, the area code has to be ... If this criteria doesn't work for you ... codes (10 digit numbers, only 7 digit numbers). ...
    (microsoft.public.access.queries)
  • Re: Retrieving phone numbers from Word documents using VBA
    ... extended it to 15 characters, because in some cases, there are extension ... The client has just made things very simple for you. ... the area code plus the next 10 characters following the area code. ... Right now I just pull out the entire sentence and I ...
    (microsoft.public.word.vba.general)
  • Re: Retrieving phone numbers from Word documents using VBA
    ... The client has just made things very simple for you. ... the area code plus the next 10 characters following the area code. ... Right now I just pull out the entire sentence and I ...
    (microsoft.public.word.vba.general)
  • Re: form validation
    ... bcc or anything that would be used for e-mail injection vulnerability) ... Phone number (has to be in the format 555-5555) ... Address has to be stripped of all illegal characters like slashes, ...
    (comp.lang.php)