close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Validate email field against database records

Thread began 8/15/2012 9:41 am by info4753 | Last modified 8/17/2012 3:11 am by info4753 | 844 views | 6 replies |

info4753

Validate email field against database records

I have a standard registration form with an email field that is validated to be a correct email entry. Now I'd like to add an additional validation to the email field. The email address that the user enters show be validated against a list of allowed email endings like:

@ibm.com
@apple.com
@webassist.com

I've tried to use the server validation at insert, with like entry as validation type and the recordset field as server variable. But the validation does not seem to work...

Thx for any help.

Sign in to reply to this post

Jason ByrnesWebAssist

you will need to use the regular expression validation type for this and use the following regular expression:

/^[A-Z0-9._%-]+@(apple.com|ibm.com|webassist.com)$/i
Sign in to reply to this post

info4753

Thx Jason. How do I connect this expression with my database table where all the mail endings are saved?

(apple.com|ibm.com|webassist.com ... are all located in a mysql table)

Sign in to reply to this post

Jason ByrnesWebAssist

the validation toolkit wizard does not support using dynamic data in regular expression validation. It will require some hand coding to accomplish, and depends on how the database is set up.


Is the database set up so that one record contains a pipe separated listing of the domains:

+----------|----------------------------------+
| domainID | domainNames |
+----------|----------------------------------+
| 1 | apple.com|ibm.com|webassist.com |
+----------|----------------------------------+




or is there a separate record for each allowed domain?

+----------|---------------+
| domainID | domainNames |
+----------|---------------+
| 1 | apple.com |
+----------|---------------+
| 2 | ibm.com |
+----------|---------------+
| 3 | webassist.com |
+----------|---------------+




Once i know the answer to that question, i can give you instructions for modifying the validation code.

Sign in to reply to this post

info4753

Thx Jason.

There is a separate record for each allowed domain.

But if it's easier to do it the other way, I can also just use one record that contains a pipe separated listing of the domains.

Sign in to reply to this post

Jason ByrnesWebAssist

ok, you will need to create a recordset to return the allowed domains. After the recordset code, add the following code to loop through it and create a new variable that contains a pipe separated list of domains:

php:
<?php 

$okDomains 
"";
do {
    
$okDomains .= $row_recordsetName['domainName']."|";
} while (
$row_recordsetName mysql_fetch_assoc($recordsetName)); 
$okDomains substr_replace($okDomains,"",-1);
?>




when you add the regular expression validation it will create a line similar to this:

php:
$WAFV_Errors .= WAValidateRX(((isset($_POST["emailField"]))?$_POST["emailField"]:"") . "","/^[A-Z0-9._%-]+@(apple.com|ibm.com|webassist.com)$/i",true,1);



edit that to use the $okDomains variable instead of the static listing of domains:

php:
$WAFV_Errors .= WAValidateRX(((isset($_POST["emailField"]))?$_POST["emailField"]:"") . "","/^[A-Z0-9._%-]+@(".$okDomains.")$/i",true,1);




make sure that the code order is correct, the validation may be placed before the recordset. The order needs to be:
-recordset
-do to create the $okDomains variable
-Validation

Sign in to reply to this post

info4753

Works perfect! Thanks a lot Jason.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...