joe_john Posted April 27, 2014 Share Posted April 27, 2014 (edited) 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 April 27, 2014 by joe_john Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/ Share on other sites More sharing options...
joe_john Posted April 27, 2014 Author Share Posted April 27, 2014 (edited) 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 April 27, 2014 by joe_john Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/#findComment-1477448 Share on other sites More sharing options...
Ch0cu3r Posted April 27, 2014 Share Posted April 27, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/#findComment-1477460 Share on other sites More sharing options...
joe_john Posted April 27, 2014 Author Share Posted April 27, 2014 (edited) 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 April 27, 2014 by joe_john Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/#findComment-1477463 Share on other sites More sharing options...
Ch0cu3r Posted April 27, 2014 Share Posted April 27, 2014 Oh yeah the regex should of been /^([\d\.()\:\- ]+)(ext(ension)?:\s+\d+)?$/i So this regex code that you gave me will allow numbers, letters, -, dot, ( and ), : and spaces Is that right? Yes. you can test it out here http://www.regexr.com/38p1e Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/#findComment-1477469 Share on other sites More sharing options...
joe_john Posted April 27, 2014 Author Share Posted April 27, 2014 (edited) Oh yeah the regex should of been /^([\d\.()\:\- ]+)(ext(ension)?:\s+\d+)?$/i Yes. you can test it out here http://www.regexr.com/38p1e Hi ok, just did some testing. seems ok, but not quite. for example, this fails: (323) 894-94.39 ext 55 not sure why. Edited April 27, 2014 by joe_john Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/#findComment-1477470 Share on other sites More sharing options...
Ch0cu3r Posted April 27, 2014 Share Posted April 27, 2014 Change this part of the regex (ext(ension)?: to (ext(ension)?:? Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/#findComment-1477472 Share on other sites More sharing options...
joe_john Posted April 27, 2014 Author Share Posted April 27, 2014 you are awesome, thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/288061-validation-regex-php/#findComment-1477474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.