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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

Correct Spellings (i.e., replacing hotmial.com with of hotmail.com, etc.)

I have a form where user enters their email address. The problem is, sometimes user mistakenly enters incorrect domain name spelling i.e., hotmial.com instead of hotmail.com. I am hoping an expert can provide me with some JS which will automatically change incorrect spellings (which would be defined in script so that I can add a bunch of them) using onChange event.

For exmaple, JS would include something like:

IF hotmaol.com, replace with hotmail.com;
IF hotmal.com, replace with hotmail.com;
IF hotmial.com, replace with hotmail.com;
IF yaho.com, replace with yahoo.com;
IF ail.com, replace with aol.com;
etc.

Thanks!

Casey
0
cbradstreet
Asked:
cbradstreet
1 Solution
 
AlopederiiCommented:
<script>
rlist=new Array()

//     Chose your delimiter!
//     You must change this if you separate the
//     good e-mail address from the bad with anything
//     other than a comma.

delim=","



//     Declare your list of replacements, with the following format:
//     rlist[rlist.length]="bad_email,corrected_version"

rlist[rlist.length]="hotmial.com,hotmail.com"
rlist[rlist.length]="yaho.com,yahoo.com"
rlist[rlist.length]="ail.com,aol.com"

function correctit(tocorrect){
for(i=0;i<rlist.length;i++){
temp=rlist[i].split(delim)
tocorrect=tocorrect.split(temp[0]).join(temp[1])
}
return tocorrect
}
</script>

Put the above code in your document.  Then to use it, just add:
onBlur="this.value=correctit(this.value)"



Example:
<HTML>
<script>
rlist=new Array()

//     Chose your delimiter!
//     You must change this if you separate the
//     good e-mail address from the bad with anything
//     other than a comma.

delim=","



//     Declare your list of replacements, with the following format:
//     rlist[rlist.length]="bad_email,corrected_version"

rlist[rlist.length]="hotmial.com,hotmail.com"
rlist[rlist.length]="yaho.com,yahoo.com"
rlist[rlist.length]="ail.com,aol.com"

function correctit(tocorrect){
for(i=0;i<rlist.length;i++){
temp=rlist[i].split(delim)
tocorrect=tocorrect.split(temp[0]).join(temp[1])
}
return tocorrect
}
</script>
<BODY>
<FORM NAME="form1">
<INPUT NAME="test" onBlur="this.value=correctit(this.value)">
</FORM>
</BODY>
</HTML>
0
 
cbradstreetAuthor Commented:
Thanks Alopederii!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now