Jump to content

Default email address


WestPress

Recommended Posts

Below is a rule for returning a company formatted email address in lower case (as email addresses should be) so that a user does not have to enter the whole thing and possibly fubar the email address.

 

It searches the input for the "@" symbol which suggests that they want a different email address (i.e. like a sales person might have an alternate email address, etc.)

 

There are two variables that the rule uses. One is the actual email field. The second contains the company domain, you should change "testcompany.com" with your company domain.

 

emailField = ToLower(Field("email"));
cDomain = ToLower("@testcompany.com");

if (Field("email") != "") {
   if (Field("email").search("@") > -1)
       return emailField;
   else
       return emailField + cDomain;
} else {
   return "";
}

Link to comment
Share on other sites

  • 3 weeks later...

I have a basic email rule, that says if there's an entry in the email field then add on "@testcompany.com". If the email field is blank, do nothing.

 

I need to make it so that if someone enters a full email john@testcompany.com it strips out the @testcompany.com and uses the rule, because if people mess up and enter in more than their name, it will be john@testcompany.com@testcompany.com

 

thoughts?

Link to comment
Share on other sites

I have a basic email rule, that says if there's an entry in the email field then add on "@testcompany.com". If the email field is blank, do nothing.

 

I need to make it so that if someone enters a full email john@testcompany.com it strips out the @testcompany.com and uses the rule, because if people mess up and enter in more than their name, it will be john@testcompany.com@testcompany.com

 

thoughts?

 

Isn't that exactly what the rule in the original message in this thread does? That is, if I run cdaters's rule with the field value set to "john@testcompany.com", it returns exactly that, not "john@testcompany.com@testcompany.com". What are you doing differently?

Link to comment
Share on other sites

The original posted rule does eliminate the chances of getting "joe@testcompany.com@testcompany.com", BUT for my company they want the domain to have caps in it so it's "@TestCompany.com" so if someone types "@testcompany.com" I want it to replace with "@TestCompany.com". So I always want to use the predetermined domain name, also in case of typos.
Link to comment
Share on other sites

The original posted rule does eliminate the chances of getting "joe@testcompany.com@testcompany.com", BUT for my company they want the domain to have caps in it so it's "@TestCompany.com" so if someone types "@testcompany.com" I want it to replace with "@TestCompany.com".

Okay, then just do a replace to change the string to whatever you want, like so:

 
var emailField = Field("email");
var cDomain = "@TestCompany.com";
if (!emailField)
 return "";
//else  
if (emailField.search("@") > -1)
   return emailField.replace(new RegExp(cDomain, "gi"), cDomain);
//else
return emailField + cDomain;

So I always want to use the predetermined domain name, also in case of typos.

Well, I'm not sure you can "cleanse" every possible typo in user-entered data, but you can certainly change the capitalization, as above. Of course, domain names in web and email addresses are case-insensitive by definition, so it's merely an aesthetic change, as alluded to in the original post in this thread:

Below is a rule for returning a company formatted email address in lower case (as email addresses should be)

Given the aforementioned case-insensitive nature of domain names, I'm not sure I agree that addresses "should be" in lower case (at least not the domain name part). But, your requirements are clearly different from the original poster's, and they seem to be different from what you stated in your first post as well.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...