Email address validation pattern

First off, I'm using JDK 1.4.2_07. What I'm trying to do is validate email addresses with the String.matches(String pattern) function. What I'm having a problem with is coming up with the regex pattern that represents any syntactically valid email address. If someone has a regex pattern that does represent any syntactically valid email address, I would appreciate it if you posted it in a reply to this message. Thanks!
--Ioeth                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Here is the struts implementation of email address validation:
<validator name="email"
classname="org.apache.struts.validator.FieldChecks"
method="validateEmail"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.email">
<javascript><![CDATA[
function validateEmail(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oEmail = new email();
for (x in oEmail) {
if ((form[oEmail[x][0]].type == 'text' ||
form[oEmail[x][0]].type == 'textarea') &&
(form[oEmail[x][0]].value.length > 0)) {
if (!checkEmail(form[oEmail[x][0]].value)) {
if (i == 0) {
focusField = form[oEmail[x][0]];
fields[i++] = oEmail[x][1];
bValid = false;
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
return bValid;
* Reference: Sandeep V. Tamhankar ([email protected]),
* http://javascript.internet.com
function checkEmail(emailStr) {
if (emailStr.length == 0) {
return true;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray == null) {
return false;
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat) == null) {
return false;
var IPArray = domain.match(ipDomainPat);
if (IPArray != null) {
for (var i = 1; i <= 4; i++) {
if (IPArray[i] > 255) {
return false;
return true;
var domainArray=domain.match(domainPat);
if (domainArray == null) {
return false;
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if ((domArr[domArr.length-1].length < 2) ||
(domArr[domArr.length-1].length > 3)) {
return false;
if (len < 2) {
return false;
return true;
}]]>
</javascript>
</validator>

Similar Messages

  • Help needed in email address validation !

    Hi all,
    I am developing a web page in which there is a text box and a submit buttion. User enters his email id and clicks the button. As soon as the button is clicked, the email- address validation should be done.
    some thing like,
    only one @ shold be there,
    the address should terminate with .net, .com, .org.....
    there should not be any special characters like / , ?, < > \ etc..;
    It should be in JSP or JAVA Script
    Can anyone help me ????
    Regards
    AShvini

    function validateEmail(email) {
        // A very simple email validation checking.
        // you can add more complex email checking if it helps
        var splitted = email.match("^(.+)@(.+)$");
        if(splitted == null) {
            return false;
        if(splitted[1] != null ) {
            var regexp_user=/^\"?[\w-_\.\']*\"?$/;
            if(splitted[1].match(regexp_user) == null) {
                    return false;
        if(splitted[2] != null) {
            var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
            if(splitted[2].match(regexp_domain) == null) {
                var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
                if(splitted[2].match(regexp_ip) == null) {
                        return false;
            }// if
            return true;
        return false;
    }Here's one in JS. A little bit of modification could make it suited to your requirements!

  • EMail Address Validation - Shell Script

    Hi,
    I have a custom concurrent program (Shell Script Program). One of the input parameter is Email address.
    In my code, I need to validate email address format (Ex: [email protected])
    Can anyone paste the code snippet.
    I have tried with the below validation
    case $EMAIL_ID in
         *@?*.?*) echo "Email Address Validated.";;
         *) echo "Invalid Email Address. Please enter the correct format of email address and re-run the program";
    exit 1;;
    esac
    This validation is failing in this scenario xxx,[email protected] / xxx [email protected] (If user enters the email address with comma or a blank space. This validation is returning success message)
    Regards
    BS

    Please look up the syntax for this by typing
    man mailx
    on the shell command prompt.
    Please stop asking Unix specific questions in an Oracle forum. There are more than enough Unix forums on the Internet.
    Please refrain from asking further doc questions here.
    You are in gross violation of the 'Forums Etiquette' post.
    Sybrand Bakker
    Senior Oracle DBA

  • Email Address Validation in JavaScript?M

    Hi, everyone,
    I need to validate the email address in javascript.
    Does anyone has a COMPLETED solution?
    Any reply would be valuable.
    Thank you in advance.

    BalusC wrote:
    Modi wrote:
    you can validate email address using java file.
    Take a look here
    [http://www.devdaily.com/blog/post/java/java-email-address-validation-class|http://www.devdaily.com/blog/post/java/java-email-address-validation-class]
    This is written by a 10 year old child and this identifies [email protected] as valid. It is not.
    [http://www.devx.com/tips/Tip/28334|http://www.devx.com/tips/Tip/28334]
    This identifies [email protected] as valid. It is not.
    [http://java-servlet-jsp-web.blogspot.com/2009/06/best-url-and-email-validation-using.html|http://java-servlet-jsp-web.blogspot.com/2009/06/best-url-and-email-validation-using.html]
    This does not validate .museum tld's, nor email addresses with RFC822/5322 valid characters like ~, #, & and so on.
    With other words, come up with better suggestions, kid.
    >
    >you can validate email address using java file.
    Take a look here
    [http://www.devdaily.com/blog/post/java/java-email-address-validation-class|http://www.devdaily.com/blog/post/java/java-email-address-validation-class]
    This is written by a 10 year old child and this identifies [email protected] as valid. It is not.
    [http://www.devx.com/tips/Tip/28334|http://www.devx.com/tips/Tip/28334]
    This identifies [email protected] as valid. It is not.
    [http://java-servlet-jsp-web.blogspot.com/2009/06/best-url-and-email-validation-using.html|http://java-servlet-jsp-web.blogspot.com/2009/06/best-url-and-email-validation-using.html]
    This does not validate .museum tld's, nor email addresses with RFC822/5322 valid characters like ~, #, & and so on.
    With other words, come up with better suggestions, kid.
    Okey fine.
    Now see these links
    [https://glassfish.dev.java.net/source/browse/glassfish/mail/src/java/javax/mail/#dirlist|https://glassfish.dev.java.net/source/browse/glassfish/mail/src/java/javax/mail/#dirlist]
    [https://glassfish.dev.java.net/source/browse/glassfish/mail/src/java/javax/mail/internet/InternetAddress.java?rev=1.6&view=markup|https://glassfish.dev.java.net/source/browse/glassfish/mail/src/java/javax/mail/internet/InternetAddress.java?rev=1.6&view=markup]
    I guess u will get right answer from these links and code also whatever u wants to do.
    might be it will not completely useful but i think u will get some ideas.

  • Email address validation, is there a way to use Regex or other fuzzy searching?

    I would like to use PL/SQL for Email address validation, is there a way to use Regex (regular expressions) or some other fuzzy searching for that? Using % and _ wildcards only take you so far...
    I need something that will verify alphanumeric charectors (no ",'.:#@&*^ etc.) any ideas?
    Current code:
    if email not like '_%@_%.__%' or email like '%@%@%' or email like '% %' or email like '%"%' or email like '%''%' or email like '%
    %' then
    The last line is to make sure there are no linebreaks in the middle of the email address, is there a better way to signify a line break, like \n or an ascii equivilent?

    Michael:
    The as noted in the previous post, DBI is a Perl package that allows Perl to talk to various databases, including Oracle. We use DBI on several UNIX servers, and it does not require ODBC, and I have always found it to be extremely quick. Things may be different in the Windows world.
    If you are spooling files out to run through Perl anyway, you may want to take a look at DBI. You could probably modify your existing scripts to use DBI fairly easily. The basic structure using DBI is like:
    use DBI;
    my dbh;       # A database handle
    my sth;       # A statment handle
    my sqlstr;    # SQL statement
    my db_vars;   # Variables for your db columns
    # Connect to the database
    $dbh = DBI->connect( "dbi:Oracle:service_name","user/password");
    $sqlstr = 'SELECT * FROM emp WHERE id = ?' # even takes bind variables
    #Prepare statement
    $sth = $dbh->prepare($sqlstr);
    $sth->execute(12345);  # Execute with values for bind if desired
    # Walk the "cursor"
    while (($db_vars) = $sth->fetchrow_array()) {
       your processing here

  • BP Email Address validation

    Hi,
    Is there anyway to turn off email address validation which occurs when creating Business partner.
    For example, abc.com@acb is an invalid email id and the system doesnt allow to save BP. But i want to save the BP even though email id is invalid.
    Thanks,
    Karthik.

    Hi Kartik,
    Only way to remove validation is to change the standard code.Go to program LSZA0F33 and comment FM
    SX_INTERNET_ADDRESS_TO_NORMAL.Please refer the below mentioned code.
    *{   DELETE         PDCK902820                                        1
    *\  CALL FUNCTION 'SX_INTERNET_ADDRESS_TO_NORMAL'
    *\       EXPORTING
    *\            address_unstruct    = unstruct
    \           COMPLETE_ADDRESS    = 'X'
    *\       IMPORTING
    *\            address_normal      = normal
    \           local               =
    \           domain              =
    \           COMMENT             =
    \            addr_normal_no_up_with_comment                   "1280i
    \                                = normal_w_umlaut            "1280i
    *\       EXCEPTIONS
    *\            error_address_type  = 1
    *\            error_address       = 2
    *\            error_group_address = 3
    *\            OTHERS              = 4.
    *\  IF sy-subrc <> 0.
    \550i+
    *\    error_table-msg_id     = sy-msgid.
    *\    error_table-msg_type   = sy-msgty.
    *\    error_table-msg_number = sy-msgno.
    *\    error_table-msg_var1   = sy-msgv1.
    *\    error_table-msg_var2   = sy-msgv2.
    *\    error_table-msg_var3   = sy-msgv3.
    *\    error_table-msg_var4   = sy-msgv4.
    \    error_table-fieldname  = 'SMTP_ADDR'.                   "863i
    *\    APPEND error_table.
    \    worst_error = c_error_occurred.                         "863u
    *\    IF g_check_address IS INITIAL.
    \      error_table-msg_type = c_warning_occurred.            "863u
    *\      MODIFY error_table
    \      TRANSPORTING msg_type  WHERE msg_type = c_error_occurred."863u
    \      worst_error = c_warning_occurred.                     "863u
    *\      help_smtp = smtp-smtp_addr.
    *\      TRANSLATE help_smtp TO UPPER CASE.                 "#EC TRANSLANG
    *\      CONDENSE help_smtp.
    *\      p_wa_adr6-smtp_srch = help_smtp.
    *\    ENDIF.
    *\    returncode = worst_error.
    \550i-
    *\  ELSE.
    *\    TRANSLATE normal TO UPPER CASE.                      "#EC TRANSLANG
    *\    p_wa_adr6-smtp_srch = normal-address.
    \    p_wa_adr6-smtp_addr = normal_w_umlaut-address.          "1280i
    *\  ENDIF.
    *}   DELETE
    *{   INSERT         PDCK902820                                        2
    Code inserted
        p_wa_adr6-smtp_srch = unstruct-address.
        p_wa_adr6-smtp_addr = unstruct-address.

  • Apple email address validation

    Since upgrading to iCloud, I am now regularly being told that I do not have a valid primary email address. 
    This pretty much happens every time I try and purchase something though iTunes or the app store.  It directs me to the account section, where I find no primary email address.  So far I have tried
    1.  Selecting the @mac.com address and hitting the make primary button.  (This updates it occasionally)
    2.  Adding a separate email address, making it primary and validating, then re adding my @mac email address and making it primary.
    it works for a couple of days, then I get the warning again when I am trying to upgrade an app, buy an app, buy some music or do anything with my online account.
    I am getting fairly annoyed with it now.  Is this a regular problem, or am I just 'lucky'.
    What an I do to stop this happening?  All help appreciated.

    HI,
    I relented and tried it.
    I could add an email or at least start the process.
    On Adding it it said it was sending the email.  Initially I spelt the email wrong and it said it was sent but nothing arrived.
    Once I sorted that It did send an email which had  Verify Link which then wanted me to enter my Apple ID (it was an Apple Page) and password.
    That page accepted it but Messages still showed the Greyed Out email with no Enabled tick saying Waiting to Verify and Details.
    This time the Details option would not let me remove the email from Messages.
    Visiting the Apple ID web site and logging in showed bit the misspelt ones and the one I was trying to add which did say it was verified.
    On the iPhone it did wait until I opened the screen but then I got he Pop ups.
    It tried to add the one I have had an issue with for sometime (Again) I said no to Adding it.
    Then the new email popped up and I said No to that as well.
    On then checking the Messages Settings both had in fact been added.
    I then removed the Emails from the Apple ID page and it then was removed from the iMessages account in the Mac version.
    7:49 pm      Monday; January 26, 2015
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • Multiple Email Address Validation in Siebel 8

    Hi,
    I am trying to find out the way through which we can validate multiple email addresses in siebel 8 while performing F9 functionality.I mean, in the "To" field if we want to include several mail ids, then it should be able to validate the mail ids with names in double quotes and the mail id in angular braces <> and the next mail id seperated by comma, for example:
    It should allow: "abs mehra" <[email protected]>, "jkl kala" <[email protected]>,...
    Thanks
    Edited by: 915268 on Feb 17, 2012 5:29 AM
    Edited by: 915268 on Feb 17, 2012 5:34 AM

    Hi, try these links maybe they will be useful :)
    http://onlysiebel.blogspot.com/2011/05/email-validation-script-in-siebel.html
    http://siebelunleashed.com/validating-email-address-siebel/
    Regards,

  • Email address validation

    Hi,
    We recently deployed a basic questionnaire being used by military personnel.  We turned on the "Submission Receipts" option so that respondents could receive a copy of their submission.  We have discovered that due to the elaborate format of some military email addresses (First.Middle.Last.role(civ, ctr, mil)@whatever.mil), the system was not allowing the results to be recorded because it deemed the email address invalid.  Can someone verify whether or not this is indeed an issue in the FormsCentral processing?
    Thanks!

    Previously, we had the "Submissions  Receipts" option turned on and used an email address field.  We got reports that people with .mil email addresses were getting errors that the email address was invalid and subsequently the data did not seem to be captured.  So, we turned off the option and changed the "Email" field to a text field so that it didn't perform the validation check.  Since that field is now optional, it isn't a big issue but might be of some use in the future.
    This morning I went to share access to the form to an employee who works for a company with a .us email address.  When I typed in her email address, the interface said it was an invalid email address.  I just tried again and this time it worked fine so if you fixed it, thanks for the quick turnaround.
    If you require more detailed information or a link to the form, please email me directly.  Thanks!

  • Email Address Validation in Forms

    Hi everyone,
    I volunteer as a web designer for a local nonprofit newspaper
    here in Cleveland, and am having a heck of a time with spambots and
    our email form. Bots send all kinds of garbage on casinos, viagra,
    porn, etc. several times throughout the day to the point that we're
    overwhelmed!
    My question is, how do I validate email addresses so that
    fake addresses cannot submit the form? Is there a line of code I
    can include?
    The form is located
    here.
    Thank you!

    Joe:
    Is there any way to check for an SPF record?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Joe Makowiec" <[email protected]> wrote in
    message
    news:[email protected]...
    > On 04 Dec 2006 in macromedia.dreamweaver, Jeff from
    Cleveland wrote:
    >
    >> I volunteer as a web designer for a local nonprofit
    newspaper here
    >> in Cleveland, and am having a heck of a time with
    spambots and our
    >> email form. Bots send all kinds of garbage on
    casinos, viagra,
    >> porn, etc. several times throughout the day to the
    point that we're
    >> overwhelmed!
    >>
    >> My question is, how do I validate email addresses so
    that fake
    >> addresses cannot submit the form? Is there a line of
    code I can
    >> include?
    >>
    >> The form is located
    >>
    http://www.nhlink.net/plainpress/html/contactus.htm.
    >
    > I'm going to differ with my esteemed colleagues.
    CAPTCHAs aren't the
    > way to go. The big reason is that they are a disaster
    for
    > accessibility; in addition they look like crap, and they
    aren't
    > reliable. See the article at Wikipedia for some pros and
    cons:
    >
    >
    http://en.wikipedia.org/wiki/Captcha
    >
    > There are a few things you can do:
    > - I haven't yet seen a way to check an email address for
    validity. You
    > can, however, check if the domain name submitted has an
    MX record (Mail
    > eXchange). PHP:
    >
    > $valid_domain = checkdnsrr($domain, 'MX');
    >
    >
    http://www.php.net/manual/en/function.checkdnsrr.php
    >
    > - Check for '@' characters in any field other than the
    return address.
    > Very few legitimate correspondents will use them; many
    spammers use
    > them in an attempt to spoof the form (do a web search
    for 'php mail
    > injection).
    >
    > - Use an added dropdown list field that has to be
    changed in order to
    > check if there is a real user there:
    >
    > <select name="okaytosend" id="okaytosend">
    > <option>Change this item</option>
    > <option value="xyzzy">OK to send</option>
    > </select>
    >
    > The following two methods work for now; no guarantee
    when spambots will
    > catch up with them:
    > - Spambots (at least the ones I've seen) don't
    understand cookies, so
    > you can set a cookie or start a session on the form
    page, and check for
    > the cookie or session on the form processing page.
    >
    > - Spambots (at least the ones I've seen) don't
    understand javascript,
    > so you can use an (external) script to write a hidden
    field. If you
    > have the field, high probability it's a person; if you
    don't, high
    > probability it's a bot. (I keep track of javascript use
    on one of my
    > sites; at last check, about 1.7% of site visitors had
    javascript
    > disabled, so you'll get a few false negatives.)
    >
    > --
    > Joe Makowiec
    >
    http://makowiec.net/
    > Email:
    http://makowiec.net/email.php

  • Email address Validation routine

    Hi ,
    I am just wondering how can we validate a email address with @ and .com so that data flowing to email filed is sent to error dtp if validation fails.
    PLease let me know

    Write a characteristic routine where it checks the source value of the e-mail address for '@' and '.com' and if it doesn't contain these, then set the return code to other than 0. Here's some example code:
    DATA: l_email(60) TYPE c.
    CONSTANTS: c_atsign(1) TYPE c VALUE '@',
                         c_domain(4) TYPE c VALUE '.com',
                         c_error TYPE sy-subrc VALUE 8.
    l_email = SOURCE_FIELDS-email.
    IF l_email CO c_atsign
       AND l_email CO c_domain.
         RESULT = l_email.
    ELSE.
       sy-subrc = c_error.
    ENDIF.
    The only thing that concerns me about this is that if the domain for the e-mail is '.net', '.org', etc, this will fail. You may have to account for the different possible domains.

  • Email address validation with JavaMail

    Hi there,
    Does anyone know whether the JavaMail library provides any means to validate email addresses? My first thought was to use the AddressException but this doesn't work. I was able to construct address such as
    InternetAddress a1 = new InternetAddress("foo");
    InternetAddress a2 = new InternetAddress("--------foo---------");
    InternetAddress a3 = new InternetAddress("?$@%##$%??%$$#");
    without the AddressException being thrown... Any comments would be appreciated.
    Regards,
    Arman

    I use this simple test and is does the trick for me.
    * @param address :string met email adress zoals
    [email protected]
    * @return      :true valid address, false invalid
    address.
    private static boolean validmailadress(String address)
    // address should must have a length of minimal 3
    examp: a@b
    if (address.length()<3) return false;
    if(address.indexOf("@")==-1) return false;
    return true;
    Regards,
    Wil.I think this is wrong. Take for example, would you call this valid?
    abc@abc
    Your code will call this valid, but to you and, it is very wrong. All you have to do is check that there is a '.' anywhere after the '@' and there is something after that.
    Well, I will write one and post it here later.

  • Email address validation  -- Help plz

    I'm trying to validate set of email addresses from database and generate report on invalid email addresses
    I was able to validate if there is any syntax error in email address string.
    But I need to validate even the domain whether it exists or not.
    Can any one of you help me out in this regard.

    You're going to need to parse the address enough to extract the domain name.
    Then you can use the java.net.InetAddress class to see if that's a valid host name.
    But of course that still doesn't tell you if the email address is actually valid.
    See the JavaMail FAQ.

  • Email address validation fails (IM for Nokia - Cha...

    I've installed 'IM for Nokia - Chat on the go' in my Nokia C6-01, i am unamle login using my gmail adderss that has a (.) dot in it. whereas its an valid email id. if you could fix this issue that will be great. Thanks.
    Moderator's Note: This post has been edited to remove the user's email address. For security reasons, we do not encourage posting of personal information in a public forum.

    IT would help if the people that are working this issue would post the resolve of their problems. Every post I see with this problem someone from oracle replies with needing the source project to replicate the issue and the thread dies....

  • How to Test if an Email Address Exists?

    So we have all been doing email address validation for awhile which I know how to do, but validation only tests if an email address is entered in the right format.  It doesn't verify if an email address actually exists.  I am creating an application  where there will be membership fees, and so an email has to be in more than the right format, I must be positive that it actually exists when the account is created before any money changes hands.  This is critical.  Unfortunately, all of my searching for this relating to Flex or Flash Builder has yielded no results.  Does anyone know of any tutorials or blogs or articles that discuss how to test if an email address entered by a user actually exists using Flex?  or does anyone here have any suggestions on how to approach this problem?
    Thanks!

    The only definitive way is to send the user an e-mail, and have them verify the email address.
    In the past I remember researching options.  Depending on how mail servers were set up; I thought there was some way to ping a mail server and ask if the e-mail address was valid.  This functionality was turned off on most mail servers to prevent spammers from harvesting email addresses.
    Here are some good info on the general approach:
    http://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without- sending-an-email

Maybe you are looking for

  • How to get start and end time of an ESB instance in SOA 10.1.3.4

    Hi All, I am using soa 10.1.3.4 and want to track the esb instance start and end time. (For example, in case of bpel we can query the cube instance table to get creation and modify time of an instance. ) How to get that in esb? Thank you. Regards, Sa

  • Failed Exchange Server Sync Question

    Hi all my exchange server has failed so had to replace it which I have now done but im unsure about the phones. All the users phones still have the contacts and emails on but there Outlooks are effectly blank. If I sync the phones will I loose all th

  • Repository browser login error

    I started the listener. Even then I am facing the problem of opening the page. It is displaying that "unable to open the page. Page is unavailable"

  • FLASH CS5 on iPhone

    Hello, Excuse me, but I'm new to using Flash. I recently installed FLASH CS5 and I'm trying to open up a new iPhone OS flash file. But unlike various videos, tutorials, etc that I'm following on line. I don't actually seem to have this on my version.

  • Schedulebatch.cmd and Taskflows

    Hi There, Two questions. 1. Does the schedulebatch command file which runs Financial Report batches from the command-line have to be run from the reports server where it resides? That seems to be the only way I can get it it work. 2. In Taskflows on