I want to prevent duplicate email addresses during registration. How would I go about validating the text box on entry so that the same email address won't be accepted twice?
That code would not be entered in/on a text box rather when the forms is submitted you would check if it was used already. Also if you want to do it otherwise (while the user is typing) you can use ajax to help you do this.
I think is is probably most appropriate handled as a uniqueness constraint (or unique index) on that column in the database. This will ensure the integrity of the database and you can check the error message to determine whether the failed insert/update was the cause.
I know of two ways.
Way 1: Dynamically query the database and display a message such as, "This email address already is in the server, please choose another" You'd be doing the check each time the user typed into the text box.
Way 2: Have a two-phase registration where on submittal of the information, you have a validation routine execute to check that all information is acceptable - in your case, it would be to check for duplication of email addresses.
I recommend the second way I put up - it reduces server load.
I would suggest doing both the unique index on the database to protect data integrity, but also you should have validations on submit or through some ajax call that checks the email address as well.