Source Code

for file /AJAXEngine/S03_AJAXControls/ValidatorDemo.asmx

<%@ WebService Language="C#" Class="ValidatorDemo" %>
// ValidatorDemo.asmx
// Sample WebService to show the Validation Control extended by an AJAX functionality.
// Copyright (c) by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// ----- 
// 27.09.2005 created by Matthias Hertel
// 03.10.2005 published

using System;
using System.Net;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://www.mathertel.de/ValidatorDemo/", Description = "WebService to validate e-mail adresses.")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ValidatorDemo : System.Web.Services.WebService {

  [WebMethod(Description="Validate a e-mail address by checking the hostname.")]
  public bool ValidateEMail(string emailAddress) {
    bool isCorrect = false;
    
    if ((emailAddress != null) && (emailAddress.Length > 2) && (emailAddress.IndexOf('@') > 0)) {
      string hostname = emailAddress.Split('@')[1];

      isCorrect = true;
      // Dns.GetHostEntry will throw an exception if the hostname cannot be found
      try {
        IPHostEntry IPhst = Dns.GetHostEntry(hostname);
      } catch (Exception) {
        isCorrect = false;
      }

    } // if
    return (isCorrect);
  }

  // you can find more advanced server side e-mail verifications on the web.
  // Sample, See: http://www.codeproject.com/aspnet/Valid_Email_Addresses.asp
  
}



This page is part of the http://www.mathertel.de/ web site.

For updates and discussions see http://ajaxaspects.blogspot.com/.