Jump to content

validation regex php


joe_john

Recommended Posts

hi

 

I have an html/css based website. For my contact form, I am using a script called "fast secure contact form"

 

The contact form looks like this:

 

name:

email:

phone number:

message:

 

every day, I am receiving more than 20 spam messages in my inbox through the contact form. I don't want to enable captcha because it's a turn-off for my site's visitors.

 

In the options section of this script, for each field, there is something called "validation regex" where you can enter anything you want. I don't know what it means or how it works, but I understand you can ban a string of characters using validation regex.

 

Looking at the spam messages, the one thing they have in common is that in the phone number field, they put a URL. so their might put http://www.whatever.com

 

Using validation regex, how can I ban the string http? so if the phone number field contains the this exact sequence of letters h followed by t followed by t followed by p, then form does not get submitted?

 

Edit: just as a side note, another thing I could do is to allow numbers only, but some people put the word "extension" or "ext" in the phone number field, so that won't work.

Link to comment
https://forums.phpfreaks.com/topic/288061-validation-regex-php/
Share on other sites

Edit2: if banning http cannot be implemented, how about ONLY allowing

letters

numbers

:

dots

right paranthesis

left paranthesis

 

no forward slashes

 

so this would go through: (345) - 889- 9944  extension: 882

this would go through: 345.889.9944

 

but this would not go through: http://www.

Umm, downloaded that script and had a bit of play with it.

 

Try adding this regex to the Validation regex field for the phone number field

^([\d\.()\:\- ]+)(ext(ension)?:\s+\d+)?$

Then in the "Regex fail message" field type in your error message for when the phone number is not valid. If the user enters are non validating phone number the form should not submit and the error message should appear

Umm, downloaded that script and had a bit of play with it.

 

Try adding this regex to the Validation regex field for the phone number field

^([\d\.()\:\- ]+)(ext(ension)?:\s+\d+)?$

Then in the "Regex fail message" field type in your error message for when the phone number is not valid. If the user enters are non validating phone number the form should not submit and the error message should appear

 

Hi

 

I really appreciate that you downloaded the script and studied it.

People can be very unpredictable when entering their phone numbers. I want to make sure all possibilities are covered. So this regex code that you gave me will allow

 

numbers

letters

-

dot

(

)

:

space

 

Is that right?

 

Edit2: sorry to bother you, but when I tried the code, no matter if the phone number is valid or not, it says

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in public_html/xxxxx.com/contact-files/contact-form-process.php on line 368

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.