Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Error if phone field not in the right format?

the mail() function

Moderators: macek, egami, gesf

Error if phone field not in the right format?

Postby frenchie » Tue Sep 13, 2011 5:53 am

I've been using the Form2Mail Dreamweaver extension since I don't know the PHP language at all, and it's been working pretty well, although I've been getting spams lately so I added a Captcha key, but I wanted to keep the key simple (reCaptcha can be hard to read sometimes). So I believe the robots can still decode it.

All the spam I've been receiving have one thing in common: the phone number field is filled by random letters. Is there anyway to edit the PHP so that if the phone field does not have numbers it goes to the error page?
The field still needs to accept spaces, "+", "-" and".". I also want to work if it is blank, only blocking anyone filling it with only letters.

I'd appreciate very much if someone could help me out, let me know if you need more information.

Here is the code. Sorry guys, too many characters to paste it here.
frenchie
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Sep 13, 2011 5:25 am

Re: Error if phone field not in the right format?

Postby egami » Tue Sep 13, 2011 6:26 am

Code: Select all
if (preg_match('/[a-aA-Z]/',$_POST['phone_number'])) { 
  die (
"Oops.. Telephone number is horrible....");
}
 



** Disclaimer
This is quick and very dirty, but it works.
Obviously you can change the die to be anything you want it to be.. but this will get you in the general direction of where you need to go.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Error if phone field not in the right format?

Postby frenchie » Tue Sep 13, 2011 6:30 am

Hey thanks a lot! Where exactly should I put it in the code?
frenchie
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Sep 13, 2011 5:25 am

Re: Error if phone field not in the right format?

Postby frenchie » Tue Sep 13, 2011 8:24 am

I don't know PHP at all, but are you sure it's [a-aA-Z] ? It seems logical to me that it should be something like [a-zA-Z]. Let me know if I'm wrong.
frenchie
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Sep 13, 2011 5:25 am

Re: Error if phone field not in the right format?

Postby egami » Tue Sep 13, 2011 8:26 am

You're right, a-zA-Z, typo.. sorry.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Error if phone field not in the right format?

Postby frenchie » Tue Sep 13, 2011 8:29 am

No problem, thanks. Where should I insert it? Anywhere in the file?
frenchie
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Sep 13, 2011 5:25 am

Re: Error if phone field not in the right format?

Postby egami » Tue Sep 13, 2011 9:28 am

Well that I don't know, I haven't seen your script.

I would put it where you are parsing the input information, and see where it goes from there.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Error if phone field not in the right format?

Postby frenchie » Tue Sep 13, 2011 10:01 am

The script is VERY detailed and long, but for some reason they're not using the basic PHP I'm used to see.
I have tried different places, but it didn't work...

Do you mind having a quick look to help me out? The file is linked in my first post.
frenchie
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Sep 13, 2011 5:25 am

Re: Error if phone field not in the right format?

Postby egami » Tue Sep 13, 2011 12:42 pm

Well, not to be a snob (although I kind of am when it comes to my computer and the Internet), but I don't click on links that I don't know/trust.

Find where you are doing the current processing, and play around a little. Make sure you have a backup of your current code.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Error if phone field not in the right format?

Postby frenchie » Tue Sep 13, 2011 1:19 pm

Wooooo ! I found it! Thanks.

And by the way the link is to a box.net page. It just shows up the file, no download or spam or virus or anything to worry about as far as I know... (Well I had to defend the fact that I post trustworthy links!)

Is there any way to make the message a pop up box so it doesn't leave the page?
frenchie
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Sep 13, 2011 5:25 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.