views:

109

answers:

4

Given an email address, say: [email protected]

In Coldfusion, how can i validate that the email is from "google.com" and not another domain?

+1  A: 

If you are only looking for a specific domain, it might be easier to just use some string operations.

I don't know coldfusion, but something akin to

addr.lastIndexOf("@google.com")

If it's not -1, then it's from the domain you're looking for.

Chris Thompson
+1  A: 
if(email.substring(email.indexOf("@") + 1) == "google.com")
    print("valid");
Amarghosh
+6  A: 

Okay, here is the answer in CFML :)

<cfset email = "[email protected]" />
<cfif ListLast(email, "@") EQ "google.com">
Horray!
</cfif>

EDIT

Specially for Amarghosh. We can do it this way, no worries:

<cfscript>
    email = "[email protected]";
    if (ListLast(email, "@") == "google.com") {
        // here you go
    }
</cfscript>
Sergii
+1 for answering in the correct language - btw, that's a funny syntax.
Amarghosh
@Amarghosh Funny but fine! :)
Sergii
+1  A: 

You just want to compare the domain of an e-mail address?

listLast("[email protected]","@") IS "google.com"

is one way to do it.

Al Everett