Improve company productivity with a Business Account.Sign Up

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

email validation - match function

Hi,
I have this part of an email validation function which works fine:

var emailStr = "eyal@yahoo.com"
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var matchArray = emailStr.match(emailPat);
if (matchArray == null)
  return false;

I need to change the emailPat so it will accept email addresses of the pattern:
eyal.us@somedomain.co.uk
Hence accepting one or more dot (.)  characters before the @ character.

How do I do this?
Thank you.
0
eyal_barouk
Asked:
eyal_barouk
  • 9
  • 8
  • 6
1 Solution
 
jaysolomonCommented:
<script type="text/javascript">
<!--
var isEmail = function(strValue){
      var objRegExp = /^[a-z][a-z0-9]*([.\-_][a-z][a-z0-9]*)*@([a-z][a-z0-9]*.)*([a-z]{2}|com|net|org|biz|gov|pro|int|mil|edu|info|name|aero|coop|museum)$/i;
    return objRegExp.test(strValue);
}
var output = "eyal.us@somedomain.co.uk"
alert(isEmail(output));
// -->
</script>
0
 
ZvonkoSystems architectCommented:
Or like this:

var emailStr = "eyal@yahoo.com"
var emailPat = /^(\".+\"|[a-z]\w*(\.[a-z]\w*)*)@(\[\d{1,3}(\.\d{1,3}){3}]|[a-z]\w*(\.[a-z]\w*)+)$/i;
var matchArray = emailStr.match(emailPat);
if (matchArray == null)
  return false;


0
 
GwynforWebCommented:
Thje most comprehensive and practical e-mail regex I know is

<script>
function isEmail(email){
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
   
return re.test(email)
}

output = "eyal.us@somedomain.co.uk"
alert(isEmail(output));

</script>
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jaysolomonCommented:
Z

and it allows
output = "_______@somedomain.co.uk"
0
 
jaysolomonCommented:
sorry that was for gwyn
0
 
ZvonkoSystems architectCommented:
It allows: --@-.aa

0
 
ZvonkoSystems architectCommented:
And _______@somedomain.co.uk is a valid email address.

0
 
GwynforWebCommented:
Jay yes it does because it is a valid email address,a strange one yes but _ is considered an alphanumeric character.
0
 
GwynforWebCommented:
--@-.com is also valid. No one has as yet has developed a perfect email regex.
0
 
jaysolomonCommented:
No punt intended but

i will reject any dummy that trys to have a _______@_____.com email addy


There is just to many names in this world for that
0
 
jaysolomonCommented:
Mine may not be perfect but i beleive is close
0
 
ZvonkoSystems architectCommented:
Myne is perfect :-)

<script>
function isEmail(theAddress){
  return !(!theAddress.match(/^\w+([.\-]\w+)*@\w+([.\-]\w+)+$/));
}

var emailStr = "eyal.be@yahoo.com"
alert(emailStr+" : "+isEmail(emailStr));
alert("123@456.ab : "+isEmail("123@456.ab"));
</script>



(...and most comprehensive and most practical :)
LOL :-)


0
 
ZvonkoSystems architectCommented:
I mean: mostly :)
0
 
jaysolomonCommented:
LOL Zvonko and yours allows
alert("____@____.___"+isEmail("____@____.___"));
0
 
ZvonkoSystems architectCommented:
As we just now learned is the domain ____.___ allowed.
It consist of alphanumeric characters and TLD's will be soon (or are already) also allowed to be anything. So why check anyway?

0
 
GwynforWebCommented:
_______@_____.com is not vaild _ is not allowed in the hostname.

Jay yours is no where near perfect it rejects many valid ones, eg

17584c.gross/inra@123.03.201.12
Dick_R_Gratton/SPM/USDAFS@notes.fs.fed.us
abc%def@123.1.1.1

There is discussion about this at http:Q_20488313.html . The best that is possible without hundreds of lines of codes is to allow through those that are valid together with a few invalid ones.
0
 
GwynforWebCommented:
Zvonko, Yours rejects, (all of which are valid)

17584c.gross/inra@123.03.201.12
Dick_R_Gratton/SPM/USDAFS@notes.fs.fed.us
tpjones/psw_rfl@fs.fed.us
abc%def@123.1.1.1
*abc/cde@fgh.com
0
 
jaysolomonCommented:
gross/inra <-- Never had or seen an email with the slash

%def <-- Same here

i would assume anyone setting up emails addys would only use - _ .eg
john.doe
john.doe.doe

john-doe
john-doe-doe

john_doe
john_doe_doe

anyways i am the one validating my form and i will say what is allowed and if they have one of those goofy emails, then perhaps they are too goofy for me to work for or with
0
 
ZvonkoSystems architectCommented:
Slashes are not valid in internet email addresses.
They are valid in Lotus Notes internal email addresses for hierachilcal organization levels, but are converted by Domino before passed to SMTP.
The Domino admin does define the conversion rules for inbound and outbound conversion.

0
 
ZvonkoSystems architectCommented:
In Domino you can even have multiple @ in a destination address to define the adjecant mail domains.
0
 
GwynforWebCommented:
'Slashes are not valid in internet email addresses.' yes they are.

Many US Government agency addresses have slashes in them. Dick_R_Gratton/SPM/USDAFS@notes.fs.fed.us is a real email address slightly changed.

0
 
jaysolomonCommented:
well maybe one of you have more time than i so read this and the construct to it

http://www.faqs.org/rfcs/rfc2822.html
0
 
jaysolomonCommented:
from what i get a / defines a group

i may be wrong
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 9
  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now