Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Email Address Validation

Posted on 2011-10-26
4
Medium Priority
?
166 Views
Last Modified: 2012-05-12
I need to amend a function that will prevent users from entering an @gmail or @msn or @yahoo email address to a web based CRM application

The code attached works fine and warns if the format of the address is not correct.

However, based on this script, could someone help with changes required to prevent the above from happening.

Many thanks
function emailvalidation(x,y) 
{ 
if (x.length>0) 
{ 
apos=x.indexOf("@"); 
dotpos=x.lastIndexOf("."); 
lastpos=x.length-1; 
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{ 
Valid = false; 
ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] "+ CRM.GetTrans("GenCaptions","BadMailAddress"); 
} 
} 
}

Open in new window

0
Comment
Question by:MimUK
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 1000 total points
ID: 37031397
In principle quite simple but when you get into it, quite difficult. Id do this...

Replace:

if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)

With:

if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2 || x.replace("@gmail.", "").length < x.length || x.replace("@yahoo.", "").length < x.length || x.replace("@msn.", "").length < x.length || x.replace("@googlemail.", "").length < x.length)


I added googlemail.com as it is synonymous with gmail.com.

0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 37031403
You could if you wanted to get clever with it, add all these restricted domains as translations in CRM and that way you could rewrite the function so that the function loops around checking whatever the end customer has added to translations so the list could be modified without altering the script.

Depends how clever you wanted to be with it.

0
 

Author Closing Comment

by:MimUK
ID: 37031433
Great Thanks.
Works a Treat
0
 

Author Comment

by:MimUK
ID: 37781227
Having deployed the script...

We have found that if the user enters @MSN or @Gmail the validation doesn't work as the expression is case sensitive.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question