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.

Edited by joe_john
Link to comment
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.

Edited by joe_john
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Edited by joe_john
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.