Need help isolating specific domain name extensions when validating emails

Dear fellow Java developers:
I am trying to write an application in Java using regexp in order to validate a form where a user submits their name, along with their email address. One thing I need to do as part of this application is isolate email addresses with certain extensions. For example, I would like to be able to test to see if a users email address has the top level domain extension ".ca", or has a second level domain extension of the form ".on.ca", ".co.uk", or ".org.uk", etc. Which means that if a user submits an email address that ends in .ca, or .on.ca, the block of code would be able to pick it out by checking against a predetermined regexp, and I would like the regexp to be able to check email addresses that contain a top level extension only(e.g. .ca), or addresses that contain a second level country code extension (e.g. .co.uk).
I tried using the following regexp in my java code, but for some reason, it is not working:
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobil|name|aero|jobs|museum)$
Like the above example, I would like a regexp that would allow me to specify the particular domain extensions that I am looking for ONLY, instead of being a generic one that allows all valid email addresses to pass through.
I have attached my java code that I am using at the moment below. For some reason, when I submit a command line argument of "[email protected]", I am always getting an output of "[email protected] is valid ? false" . Why is that? I can't figure this out, and would appreciate any help on this. I hope this question is clear to everyone.
Thanks in advance to all who reply.
package com.email;
public class Email {
         * @param args
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                if( args.length == 0 ) {
                      System.err.println( "Usage: Email [...]" );
                      System.exit( 99 );
                for( int i = 0; i < args.length; i++ ) {
                        try {
                                System.out.println( args[i] + " is valid ? " + emailVerify( args[i] ));
                        catch( Exception e ) {
                                System.out.println(args[i] + " : " + e.getMessage());
        public static boolean emailVerify(String email){
                String regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.(?:[A-Za-z]{2}|ca|uk|au)$]";
       if (email != null) {
            return email.matches(regexp);
       } else return false;
}

I wouldn't bother with a regex, but I guess ymmv. I think this is much easier to read and understand:
private final boolean isInValidDomain(final String emailAddress) {
    if (emailAddress.endsWith(".ca")) return true;
    if (emailAddress.endsWith(".on.ca")) return true;
    // etc...
    return false;
}Depending on the number of tests and how often you'll change, you may want to put them in a Database/File and read them into a collection to iterate over.

Similar Messages

  • Is it possible to restrict the ability to e-mail a pdf outside a specific domain name?

    Hello,
    I am trying to find a solution to a friends problem.  She has a quarterly publication that she sends out to big banks and financial institutions.  Recently she has had some problems with press leaks.  I am trying to find some security options for her however the task is difficult. Because these institutions have firewalls I am not sure encrypting or tracking is the right answer because the publication might not make it through. She wants users to be able to print the publication because many of the readers are older and prefer to read during their commute and at home.  Essentially I am looking for any ways to make readers think twice about sharing the information. I thought if I could restrict e-mail to a specific domain name that would help this way users can only e-mail within their specific company.  If any one has any suggestions please feel free to share. 

    Thank you Todd, I was able to get it to work but I do have a few more questions...
    1) When I tested this, at the top of the message, before any of the text I created, this showed up: This is a multi-part message in MIME format. --------------040406040801080102080500 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
    2) After the signature line, this showed up: --------------040406040801080102080500 Content-Type: image/jpeg Content-Transfer-Encoding: base64 Content-ID: /9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAA AAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0K CgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwM DAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAC5ApUDASIAAhEBAxEB/8QA HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQID AAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6 Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/
    (It was actually much longer than that)
    Is there anyway that I can get that to go away? I obviously would prefer a nice, cleanly formatted e-mail to be sent just like I would send if I were creating it on the spot.
    Thanks,
    Evan

  • I need help with resetting my ichat. When i try to login now it wont let me... it says "AOL Instant Messenger password" and then "iChat can't log in to ... because your login ID or password is incorrect. How do I reset this if I cant log in?

    I need help with resetting my ichat. When i try to login now it wont let me... it says "AOL Instant Messenger password" and then "iChat can't log in to ... because your login ID or password is incorrect. How do I reset this if I cant log in? When I try to press online the same thing pops up and I have no way of logging in or asking for help.

    Hi,
    iChat (it would help to know which version) can accept Apple IDs as valid AIM Screen Names.
    However if you have iChat 5 or earlier you cannot use ones ending in @me.com or @icloud.com issued by iCloud. (they can be used in iChat 6 or Messages as these versions make a double login to AIM and Apple to allow the use of the password).
    In addition if you are using an Apple ID for an AIM Screen Name the password still needs to keep to the 16 character limit that AIM has.
    AN @mac.com name can be used on any version of iChat  (Until the 30th June 2014)
    As it does not need a double check with Apple you can use it to log in to the AIM Web pages
    Login here with an AIM Name registered at AIM or and @mac.com name and see if you get any suspended account messages.
    Sometimes account can be suspended. Usually because something has triggered the "Unusual Activity" item.
    About a year ago many @mac.com users that travelled out of their own country found themselves suspended when they got home.
    If the Name checks out of if an Apple ID the password in known to be 16 characters or Less then do this:-
    In Lion upwards open a Finder Window and use the Go Menu whilst holding down the ALT key.
    Select the Library that appears in the menu list.
    Navigate to Preferences.
    (If you have version earlier than Lion the just navigate to ~/Library/Preferences (that's the Library in you Home - Little House icon - folder)
    Fnd com.apple.ichat.aim.plist (even if you are using Messages)
    Drag the file to the Trash and Restart the app.
    7:39 pm      Thursday; May 29, 2014
    ​  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

  • I have an error -5000 when I try to record in GarageBand..I urgen need help, I have an error -5000 when I try to record in GarageBand..I urgen need help

    I have an error -5000 when I try to record in GarageBand V10,02..I urgen need help, I have an error -5000 when I try to record in GarageBand..
    I just reinstal OSX 10,9,2 marveiks and downdload the GB.. but when I try to record, the error ocurr
    I urgen need help
    thanks

    This is probably one of the files that is required by the template you are using.
    These files are inside the iWeb app. Control click the iWeb app icon and select "Show package contents".
    You need to dig down through the folders and files to find what you want...
    Contents/Resources/da.lproj/Templates/
    If the file is missing you would need to re install the iWeb app...
    http://www.iwebformusicians.com/iWeb/iWeb-Tips.html

  • Domain name extensions

    I use iweb to publish to my website hosted through godaddy.com. My domain name is bracketman.com. When I go to it iweb adds a bunch of extensions to it so in the address bar it appears as bracketman.com/Playoff_Bracket/Home.html. Is there a way to stop iweb from adding these extensions to my domain name. I know that the Playoff Bracket extension comes from the site name I enter . It won't let me leave this blank when I save my work. I am using iWeb ver 3.0.3 Thanks. bracketman.com
    Message was edited by: andyjcmrdn

    "Playoff_Bracket" is not only the name of the site in iWeb but the name of the folder published by iWeb.
    To get rid of this, you need to publish the site to a local folder and upload the contents of the folder using an FTP application rather then the folder itself....
    http://www.iwebformusicians.com/WebMusic/URLs-Favicons.html

  • Domain name changes when sent to external mail ids

    Here's the problem...
    We are sending PO's as pdf's to the vendor..
    If the vendor domain name is vendor.com and mine is company.com.
    SAP sends a mail
    To [email protected] ;[email protected]
    CC : [email protected]
    When the mail reaches the vendor it shows as
    To [email protected] ;[email protected]
    CC : [email protected]
    the domain name of person2 gets changed though person2 does get the mail...and when the purchase manager at the company looks at it in his inbox - it looks as it should be.
    I checked SOST it shows the correct mail id.This is not specific to a particular domain occurs with all domains .
    Has anyone encountered such a problem before.
    Regards
    Rani

    Hello Navjot,
    if you have some basis background you can check TCode SCOT there you can see if the mail connect for external mails is configured correctly. There shoud be at least a node for SMTP communication. If there is such node check that sending s not restricted to certain adresses. Furthermore you could check over the menu if the default domain is set properly.
    Kind Regards
    Roman

  • Do I need to register a domain name?

    Hi,
    I'm new to iWeb and have a simple question. Do I need to register my website's name or do I just type it in during the "Publish" stage?
    Thanks,
    Andrew

    You don't need to register your site name. If you want a domain name like www.mydomainname.com, then you'll have to purchase it and forward it to your site wherever it may be hosted. Where are you publishing to? If you're publishing to MobileMe there's nothing to do in iWeb but click use the File->Publish Entire Site or Publish Site Changes menu option.
    If you're publishing to a 3rd party hosting service you will need to put in the relevant site and server information for that host.
    OT

  • I need help to change user name, it does not belong to this account it belongs to my employee.

    My employee was helping me setup my Apple ID and accidently typed his username "mykizism" into the user name field when creating my apple id account..  It is now permanently attached to my Apple ID and this is not acceptable.
    My employee has also stated that his user name is private to him and wishes for it to be not publicly displayed.
    Can a moderator / host please help me with this?

    I sent your request in to the hosts.

  • Need to see the domain name displayed at the admin console login page

    I used to see the domain name at the console login page until I was running WLS 8.1 SP3.
    Now that I have SP5 I am not able to see it anymore, I am curious to know what has caused this error.
    If anyone has an answer , please reply .

    Hi,
    For accessing any application outside domain you need to have Public IP of the server where your you have put your application.
    Regards,
    Gulrez Alam

  • Need help in setting file name with special characters in attachment

    Hi
    We have a requirement where we need to set the file name that contains special characters (like Russian) and send mauil using Java mail.
    If we set the file name as such, the attachment in the email contains garbled filename
    Can you pl let me know how to resolve this?
    We should use the file name as attachment name and this will have say special characters. The receiver who gets the mail should get with the correct attachment name
    One important point.. the attachments are opened from MS outlook.
    Thanks and regards
    Ram
    Edited by: 884910 on 13 Sep, 2011 5:00 AM

    Read the FAQ carefully. You don't need to call encodeText unless you're using a really
    old version of JavaMail.
    And, it depends on whether the mail reader you're using is handling encoded parameters
    according to the (new) MIME standard, or according to the (old) non-standard hack.
    Sadly, without knowing what mail reader the recipient is using, it's impossible to use
    encoded filenames that will work everywhere.

  • Need help resetting my domain!!!

    Last year a purchased a domain. I have since deleted that domain, however now whenever I create a new site w/ iweb it continues to publish that site to my old domain. I cannot figure out how to delete this old domain from iweb.
    I subscribe to mobile me and I only want them to host my site. My site is hosted there, however whenever I hit VISIT or PUBLISH on iweb it still brings up the old domain I no longer own.
    Any ideas????

    Just log into your MMe account and go to the personal section where it has enter domain name and click remove.
    Whether you have a personal domain name there or not, iWeb is still publishing to MMe and not your domain directly, so whatever, you can still access your site by using web.me.com/username/sitename.

  • Need help with Muse PHP (JavaScript error...email)

    Hey all....
    I searched and did not see an answer for this:
    I am exporting my Muse file to HTML and keep getting this error for my Contact Us page (email issue):
    "JavaScript Error:Form PHP Script is missing from web server, or PHP is not configured correctly or your web host provider.  Check if the form PHP script as been uploaded correctly, then contact your hosting provider about PHP configuration."
    What PHP version does MUSE support....5.1?  I contacted HostGator and they just updated my PHP to 5.5 and asked me what PHP MUSE needs. HostGator says 5.1 is old and they do not support 5.1. Can anyone help me?
    Also, when I try to check PHP with: http://my-site.com/scripts/form_check.php I just get an "oops" screen, but does not verify my PHP.????
    Thanks

    Difficult to debug without the URL for the form page on your site...
    Are you using the built-in File > Upload to FTP Host in Muse? Or did you use File > Export as HTML and uploaded with some other tool?
    Does http://<insert your domain name here>/scripts/museutils.js load anything? Or does it also give an "oops" screen? If it gives an "oops" screen, that would imply not all the exported files were uploaded to your server, they weren't uploaded to the correct location, or the permissions aren't set correctly.
    For forms Muse only requires PHP 4.1 or later. PHP version is not the issue.

  • Name misspelled when sending email from phone.

    When I send an email from my phone (e.g. a pic or video), my name is spelled wrong.  When I email from my phone using my yahoo account it is correct.  Where do I go to fix this?  I have already checked the spelling of my name in my Contacts list.

    It does not get your name from your entry in the Contacts list.
    Go to:
    Settings -> Mail, Contacts, Calendars -> (your Yahoo! account) -> Account
    Check the spelling in the "Name" entry.
    Good luck!

  • Need help with set up for extensions

    I'm new to OA Framework development and am just ramping up (do have years of Java development experience) and could use some help. I've read through the OA Framework Developer Guide and gone through a few of the tutorials. My task is to add some extensions to the R12 Customer Standard pages.
    I've looked in the $JAVA_TOP at the following directory structure.
    /oracle/apps/ar/cusstd/...
    I find java classes and the server.xml files but there are no PG.xml files to work with. Are these located in a different structure? What is the best approach to obtaining the base Oracle source files to start with and for configuring your local development environment to extend R12 OA Framework pages? Do you need to include the entire $JAVA_TOP in your development client environment classpath as well?
    Thanks in advance!

    To run the oracle seeded party create/update page, you can refer &lt;&lt;your Jdeveloper Installation directory&gt;&gt;\jdevhome\jdev\myhtml\OA_HTML\test_fwktutorial.jsp.
    Create a new custom jsp similar to test_fwktutorial.jsp. Modify this JSP based on your environment and user setup. Modify the links also. With this, you should run this jsp first. By clicking the link in the JSP run, you can launch party create page.
    The error you posted in RED color is thrown because you are trying to modify the web bean hierarchy in the processFormData method. Example, setting some items property to rendered false or true. All these kind of modifications should be done in the proceeRequest method of the controller.
    Following is from DEV guide to launch the forms application.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Launching Oracle Applications Forms from OA Framework Pages
    To launch an Oracle Applications form from OA Framework, you must first define a button, link or image web
    bean. The web bean then relies on the FormsLauncher applet provided by Oracle Applications (AOL/J) to
    launch the specified form.
    Declarative Implementation
    Step 1: In the OA Extension Structure pane, select the region in which you want to create the web bean to
    launch an Oracle Applications form. Choose New > Item from the context menu.
    Step 2: Set the ID property for the item, in accordance with the OA Framework File Standards, and set the Item
    Style property to button, image, or link. You may also launch an Oracle Applications form from a submit
    button. See the Runtime Control section below for more details.
    Step 3: Set the Destination URI property of the item with a value following this format (replacing the italicized
    text as appropriate):
    form:responsibilityApplicationShortName:responsibilityKey:securityGroupKey:functionName
    For example, if you want to launch the FND Menus form, the Destination URI property should be set to:
    form:SYSADMIN:SYSTEM_ADMINISTRATOR:STANDARD:FND_FNDMNMNU
    Step 4: If you wish to pass parameters to the form, set the Destination URI property with a value using the
    following format (Note that the parameter list is delimited by a space between each "parameter=value" pair):
    form:responsibilityApplicationShortName:responsibilityKey:securityGroupKey:functionName:param1=
    value1 param2=value2 param3=value3
    Note: If you wish to send varchar2 parameter values that contain spaces, use \" to enclose the string value.
    For example, to pass in something of the form:
    TXN_NUMBER=LT INVOICE 1
    Use:
    TXN_NUMBER=\"LT INVOICE 1\"
    Step 5: Refer to the following Chapter 4 topics for information about additional properties you may need to set
    for the specific item: Buttons(Action/Navigation), Buttons (Links), or Images in Your Pages.
    *Runtime Control*
    There are no special programmatic steps necessary to launch an Oracle Applications form from a button,
    image, or link in an OA Framework page. The OAButtonBean, OALinkBean and OAImageBean support the
    special form function URL format described above for the Destination URI property. When OA Framework
    encounters this special value, it generates the appropriate URL and also adds a hidden IFrame (inline frame)
    to the OA Framework page. The hidden IFrame is the target of the FormsLauncher applet provided by Oracle
    Applications.
    Launching an Oracle Applications Form From a Submit Button
    If you wish to launch an Oracle Applications form from a submit button in an OA Framework page, you must
    use the OAPageContext.forwardImmediatelyToForm(String url) method from
    548
    oracle.apps.fnd.framework.webui.OAPageContext. An example of how to use this API is shown in the code
    sample below:
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    if (pageContext.getParameter("Apply")!=null)
    String destination =
    "form:SYSADMIN:SYSTEM_ADMINISTRATOR:STANDARD:FND_FNDMNMNU";
    pageContext.forwardImmediatelyToForm(destination);
    *Usage Notes*
    Microsoft Internet Explorer supports the IFrame element, so when you launch an Oracle Applications form from
    OA Framework, only a splash window appears. Any other windows required by the FormsLauncher applet
    use(s) the hidden IFrame as the target and therefore remain(s) hidden from the user. Netscape Navigator, on
    the other hand, does not support the IFrame element, so in addition to a splash window, the user also sees
    another window used by the FormsLauncher applet.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    let me know if you got struck.

  • Need help with changing the name.

    I got my palm pre from an uncle who lives in the states. The problem is I can't call tech support to ask them because I live in belize. The proble I have with my pre is that I have added my email account to the phone, but when I send an email, they receive it in my uncles name, my name is lanny and they receive an email form cesar, I think you can see where the problem lies. Is there anyway I can change it to my name? Please help!
    Post relates to: Pre p100eww (Sprint)

    Hello and thank you for using the Palm Help Forums!
    I would create a new Palm Profile. To do this you will need to go to the Device Info app, Reset Options, then select Full Erase. All pictures, videos, and anything else stored in the USB side of the device will be erased. I recommend that if you want to keep any of that to connect your device to a computer then click and drag everything you want to keep off of the device and onto your computer.
    After you perform the Full Erase the device is going to reboot. It is going to come up with a screen to sign in to a Palm Profile or Create a New Palm Profile. NOTE*** You will need a data connection to do this. Select Create a New Palm Profile and fill in the blanks. Once you are back into the device you can set up your email accounts again and it should display the name you created the Palm Profile with.
    I hope this helps,
    -Pat

Maybe you are looking for

  • How to find out the list of users who used Discoverer

    Dear All, We have Oracle E-Business Suite 11.5.10.2 with Disco. 4i. We need to know how we can find out the Employee ID, Responsibility, Org... who used discoverer during a specific period in the past ? For example the last year. Any help plz. Regard

  • FL does not exist in current context

    I am having a problem with my code. I have defined "state" as a global variable and the user needs to input one of 3 states. Based on the state chosen, I need to select a tax rate. I wrote an if statement to select the tax rate but, until the user in

  • PLEASE HELP ME INSTALL!

    Hi All I am trying to install iTunes 7 and it says it is unable to remove the older version of Quicktime. I tried to remove it automatically, then theough add/remove programs, then My computer - Programs - Quicktime - and deleted everything thats lef

  • ARD has blocked VNC?

    Yesterday, I installed ARD 3.7.2 on both my MacBook Pro (late 2013, retina) as well as my Mac mini (early 2009) which I run as a server.  Since rebooting after the installation I can no longer access the machine over VNC locally or remotely, via the

  • Photoshop + Epson 3800 Standard questions

    Photoshop CS4 Std., Win-XP Home SP3, calibrated monitor, ACR calibrated to the camera. Epson 3800 Standard + cover on order. While I wait for the replacement for my olde Epson 2200 to arrive, I have been spending a LOT of time trying to hunt down hin