I read this requirement somewhere few days ago. The solutions given for these were quite lengthy and inefficient. For example

  • Using string.indexOf  to check for presence of @ and dot(.)
  • Loop for all the characters and verify if @ an dot sign is present or not.

I thought that there must be a better way to do it. I did find two ways to do it.

  • Without Scripting
  • With Scripting

Before we go for solution let’s define our requirement properly

Requirement:

A person should not be able to enter an invalid email address in the field.

Solution without Scripting:

A simple expression in Validation column of the field can do the trick. The expression is as following

*@*?.?* (This expression was provided to me by Jeevan Singh a friend of mine)

But this solution is not full proof and has the following limitations

  • The error message displayed is not user friendly.
  • Not all the validations can be done. For example it fails if a user is going to enter @@dfjkd.com as email id as we cannot check if the character before @ is a valid character or not.

Solution with Scripting:

function given below will return 1 the email id provided is valid and return 0 if the email id is invalid

function ValidateEmail(emailid)
{
   var pat = /(^[\w\.\+\-=]+@[\w\.\-]+\.[\w\-]+$)/g;
   var valid = emailid.replace(pat,”Y”);
   if(valid == “Y”)
      return(1);
   else
      return(0);  
}

OkAvarageGoodVery GoodExcellent (5 votes, average: 3.8 out of 5)
Loading ... Loading ...