Search code examples
c#asp.netverification

Verify E-mails as they are typed


On my page a users (internal staff members) can type a comma separated list of e-mail addresses. What I would like to do is every time a comma is typed it checks that the newly written e-mail address is in the address book.

Currently I have the address book stored as a Hashtable for O(1) search times but I can easily switch to another data structure if it is recommended.


Solution

  • You can do that with JavaScript and AJAX to communicate with the server side.

    You can do the next steps:

    1. Create a web service that gets the string from the client (which is the email the user has typed), checks it and returns true/false.
    2. Add [ScriptService] attribute to the web service class.
    3. On the page, add an ASP.NET ScriptManager control with Scripts/ScriptReference that points to the web service from step 1.
    4. On the page, add javascript code that hooks to the onkeydown event of the emails textbox
    5. In this event handler, if the user types a comma, execute a web service request to the server with the textbox value. When the respond (true or false) is received, do whatever you need with it.

    You can read more on MSDN here and here. You might also find helpful the AutoComplete AJAX extender.