Multiple Email Validation Script in Siebel

This post is a result of my sheer frustration for not getting this right in a 100 tries. I had been trying to validate the email addresses being entered in Siebel. I tried a lot of ways to get it to work (Data Validation Manager, Runtime events, Configuration etc) but the darn thing would just not work. I had to ultimately resort to the "boo hoo"- Script!

I thought this would be useful for a lot of Siebel guys out there, will save you from all that frustration.(Checks/validates for a comma separated list of emails as well)

Code:

function BusComp_PreWriteRecord ()
{
    try
    {
        this.ActivateField("Email Address");
        if (this.GetFieldValue("Email Address") != "")
        {
            var sEmail = this.GetFieldValue("Email Address");
            var sPattern = /((\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*([, ])*)*/;
            var isValid = sEmail.replace(sPattern,"Y");
            if(isValid != "Y")
            {
                TheApplication().RaiseErrorText("Please enter a valid email address");
                return (CancelOperation);
            }
            else
                return (ContinueOperation);
            }
        else
            return (ContinueOperation);
    }
    catch (e)
    {
        throw (e);
    }
    finally
    {
        sEmail = null;
        sPattern = null;
        isValid = null;
    }
}

And last but not least. I must give credit to this post which was the only one that actually worked for me. 
Regular ​Expression ​for ​multiple ​email ​validation

Tip: It is advisable to try out string manipulation, validation scripts in a script simulator before coding it in Siebel. Saves you a lot of time and effort.(for eScript you could use the W3Schools JavaScript Simulator)

Cheers!

תגובות

פוסטים פופולריים מהבלוג הזה

Access control with EAI Siebel Adapter

Profile Attributes and Open UI

SBL-EAI-04115: Cannot connect to the server