Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex email validation with a twist 2

Status
Not open for further replies.

dougcranston

Technical User
Oct 5, 2001
326
US
I have a question. One that my meager brain can fathom but cannot resolve.

I would like use a regex function to validate whether or not the user has entered the expected @subdomain.domain.org

Specifically, I need to make sure the users key in as an example: theirname@core.company.com where @core.company.com must be there and if not fail..

I know this can be done but no thoughts..

My old snippet is:

var valemail = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

if (valemail.test(document.reportreq.reqemail.value) == true) {
}
else {
alert("You must enter your full Email Address (i.e. XXXX@company.com). Please try again.");
document.reportreq.reqemail.focus();
return false;
}

But this requirement is very specific..

Any suggestions would be greatly appreciated..

Searched here and in the faq and via search site but no luck so far...

If you know of a site that describes this or has a snippet I could look at I would really appreciate it.

Thanks in advance...

Dougc
 
make the changes denoted in red:
Code:
var valemail = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)[!]{2,}[/!][a-zA-Z0-9.-]{2,4}$/;

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
kaht,

Thanks.. That will assist me on this project and another project.

However, in reviewing your code, it will, it appears permit successful validating of any email address with this structure @subdomain.domain.org

But my real problem in this instance is, how can I check to see if that ONLY @core.company.com specifically is in the email address? as in literally, is "@core.company.com" in the string being validated?

Your correction clearly ensures that the info after the @ is wellformed, but additionally, I want to ensure that only the email addresses contain that "@core.company.com"

Admittedly, @core.company.com is not the real name, but does represent the general text that I am trying to match to.

Reasoning is emails with the subdomain.domain.com are evaluated and redirected inside the firewall.

If I allow @company.com, then the email travels out to the internet and then has to wend its way back in through the firewall, and mailserver, etc... this causes delays, and exposes email messages to the web that should remain internal.

In retrospect, maybe I should have included that in the original post, and for that I apologize.

Thanks again for your post, and hope you may have an answer to this last part.

Have a great evening.

Dougc
 
> var valemail = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
>how can I check to see if that ONLY @core.company.com specifically is in the email address?

In that case, the pattern is simpler?
[tt] var valemail = /^[a-zA-Z0-9._-]+@core\.company\.com$/;[/tt]
 
tsuji,

Fantastic.. Thanks so much..

Regex has so much power. I need to learn more, but no one in my office knows it or atleast admits it.

Thanks again.

Dougc
 
Hello,
I am new to the regular expression world. I need to validate an email (which I have found many times over in this forum - cool). The one I have been using is as follows:
Code:
/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z]{2,4}$/
I believe that does everything I need with one exception. I need to support emails with an apostrophe in the first part of the email.
Code:
whoever'whatever@somedomain.com
I tried putting in \' in the expressions ... \w\'\.- ... and that does not seem to work. Please let me know what I am missing. Thanks. I only understand parts of the expression listed above. This feels like it should be a no brainer...

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top