Regular expression for email address formats

I have the following regulare expression which I am using to validate email address format.
This allows addresses of the form
[email protected]
^[-a-zA-Z0-9._]+\@[-a-zA-Z0-9]+\.[-a-zA-Z0-9]+\.[-a-zA-Z0-9]+$
And of course this allows addresses of the form
[email protected]
^[-a-zA-Z0-9._]+\@[-a-zA-Z0-9]+\.[-a-zA-Z0-9]+$
What I'm looking for is something which will allow both.

This way
'^[-a-zA-Z0-9._]+\@[-a-zA-Z0-9.]+$' would allow both. :-)
with test_data as
( select '[email protected]' as val from dual union all
  select '[email protected]'   as val from dual union all
  select 'no#good'              as val from dual
select
  val ,
  case
    when regexp_like( val, '^[-a-zA-Z0-9._]+\@[-a-zA-Z0-9.]+$' ) then 'Y'
    else 'N'
    end
    as good
from test_data ;
VAL                  G
[email protected] Y
[email protected]   Y
no#good              NBut then again, it would also allow "[email protected]" and "[email protected]" too. So I suspect you don't really want something that simply allows your two cases to pass validation. If you want to allow only those two cases then try something like this.
with test_data as
( select '[email protected]'     as val from dual union all
  select '[email protected]'       as val from dual union all
  select '[email protected]' as val from dual union all
  select '[email protected]'      as val from dual union all
  select 'no#good'                  as val from dual
select
  val ,
  case
    when
      regexp_like
      ( val
      , '^[-a-zA-Z0-9._]+\@[-a-zA-Z0-9]+\.[-a-zA-Z0-9]+(\.[-a-zA-Z0-9]+)?$'
      ) then 'Y'
    else 'N'
    end
    as good
from test_data ;
VAL                      G
[email protected]     Y
[email protected]       Y
[email protected] N
[email protected]      N
no#good                  N--
Joe Fuda
SQL Snippets
Message was edited by SnippetyJoe - added clarification.

Similar Messages

  • Regular expression for email

    Hi all,
    Can anyone help me to create a regular expression validation for email id? I have tried many combinations from internet regarding this validation, but everyone fails on APEX, although it runs fine in .NET or JAVA.
    Expressions i tried was "^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$", i want to validate email address such as "[email protected]". Can anyone help me in this regard?
    With Regards,
    Sunil Bhatia

    Hello Sunil,
    >> Can anyone help me to create a regular expression validation for email id?
    If you are talking about an email address, it’s not clear to me why you include the ‘http’ string in your regular expression. In any case, I’m using the following:
    ^[a-zA-Z0-9]{1}[a-zA-Z0-9\.\-]{1,}@[a-zA-Z0-9]{1}[a-zA-Z0-9\.\-]{1,}\.{1}[a-zA-Z]{2,4}$Regards,
    Arie.
    Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

  • Need regular expression for oracle date format 'DD-MON-YYYY'

    Hi,
    Can anybody tell me the regular expression to validate date in 'DD-MON-YYYY'.
    My concept is i have a table with just two columns item_name and item_date
    Both fields are varchar2 and i want to fetch those records from this table which have valid date format('DD-MON-YYYY').

    If it must be a regexp, this is a starter for you, note it carries the caveats mentioned by both posters above and in the linked thread
    mkr02@ORA11GMK> with data as (select '10-jan-2012' dt from dual
      2  union all select '10-111-2012' from dual
      3  union all select 'mm-jan-2012' from dual
      4  union all select '10-jan-12' from dual)
      5  select
      6  dt,
      7  case when regexp_like(dt,'[[:digit:]]{2}-[[:alpha:]]{3}-[[:digit:]]{4}','i') then 1 else 0 end chk
      8  from data
      9  /
    DT                 CHK
    10-jan-2012          1
    10-111-2012          0
    mm-jan-2012          0
    10-jan-12            0It will not validate content, only string format.
    And to emphasis the points made in the linked thread - dates in text columns is poor design. Always.

  • Carriage Return in Expression for Email Address

    I have created an SSRS report where one column displays an email address.  Since my report is too wide, I need to have the email addresses make two lines where the new line starts at the @ sign.  I have this, but its not working.
    =Fields!Email.Value +VBCRLF + "@"
    I'm not sure how to fix this.

    Hi,
    hope it helps
    =Left("[email protected]",Instr("[email protected]","@")-1) & VBCRLF & Right("[email protected]",Instr("[email protected]","@")+2)
    http://gnanadurai.blogspot.in/

  • Help me!   Give me a  Regular Expressions for Email and URL!

    see title!
    Thank you very much!

    URL pattern:
    String proto="(\\w+)";
    String userPassAt=":(\\w+)(?::(\\w+))?@";
    String host="([^\\s:/\\<>]+)";
    String port=":(\\d+)\\b";
    String file="/([^\\s:?]*)"; //backslash not included
    String query="\\?(\\S*)"; //'?' not included
    String urlPattern=proto + ":" + possibly("//") + possibly(userPassAt) + host + possibly(port) + possibly(file + possibly(query));
    static String possibly(String s){
    return "(?:"+s+")?";
    Group numbers:
    protocol = 1
    user = 2
    pass = 3
    host = 4
    port = 5
    file = 6
    query = 7
    Regards

  • How to setup the From header  in fullname and email address format

    when I sent mail from the messaging express , the mail that I sent cannot show the sender in the fullname and email address format. I use webmail and other mail client . It show only email address. I don't know how to setup this . I use the SUN JES messaging server 6.0 SP1 .

    exactly so.
    in general, for any configutil setting:
    0=off=no
    1=yes=on

  • Checkconstraint for Email Addresses

    Hello,
    iam kind of new in oracle and i wanted to know, how to create a check-constraint for email addresses? I just want to check, if there is an @ and a . within the given varchar. I thought about something like
    CHECK email in ('@' AND '.')
    But that doesn't work. Something like with queries where like %@% with check-constraint I am looking for.
    Thanks alot
    Hauke

    Unbelievable how fast you are :-)
    Thanks a lot. With the regular expressions I didn't try yet, the other worked. But with the regular expression is a very good idea.
    So thanks again !

  • Regular Expression for IPAddress

    Hello members.....
    I am a new member to this forum
    I am in need of the Regular Expression for IPAddress...
    "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"....is the expression i wrote..But it is taking 0.0.0.0 as a valid IPAddress. (0.0.0.0 is not a valid IPAddress)
    Please reply....awaiting
    Rajeshwar

    I am in need of the Regular Expression for
    IPAddress...
    "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"
    ....is the expression i wrote..But it is taking
    0.0.0.0 as a valid IPAddress. (0.0.0.0 is not a valid
    IPAddress)Your regex matches "999.999.999.999", which (of course) isn't a vaild IP address as well.
    This one is closer, but still allows 0.0.0.0:
    \\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\bBut why not roll your own method which checks an IP address?

  • Re:java regular expression for website

      Hi All,
    I am using jdeveloper 11.1.2.3.0
    My requirement is that I have a website  attribute I need the regular expression for the website attribute
    to display the format www.google.com  www.oracle.com.
    Thanks,
    Sandeep

    Hi Sandeep,
    you can use the below code for website validation.
    <af:inputText label="" id="time" simple="true" value="" contentStyle="width:100px;" maximumLength="100">
          <af:validateRegExp pattern="^www[.][a-z]{1,15}[.](com|org)$"
                         messageDetailNoMatch="Website must be like www.google.com"
                                                                                                   hint="Website Format: www.google.com"/>
        </af:inputText>
    as per your requirement you can change the pattern.
    Thanks
    Prabhat

  • My apple id is not working on icloud because it is not in email address format.   how can i change my apple id to email format so icloud can work?

    Hello - I just purchased an iPhone 4s and would like to use iCloud but my apple id is not in email address format so when i try to sign into iCloud it won't let me use my apple id.  i tried to change my apple id through my account settings but could not find a way to do that.  i found ways to change everything else in my settings but when i pushed on the edit button to change my apple id the page didn't change.  Not sure how i can get to use iCloud?  Please help.

    You change the name of your ID at https://appleid.apple.com.  See http://support.apple.com/kb/HE40.

  • Wat should be the regular expression for string MT940_UB_*.txt to be used in SFTP sender channel in PI 7.31 ??

    Hi All,
    What should be the regular expression for string MT940_UB_*.txt and MT940_MB_*.txt to be used as filename inSFTP sender channel in PI 7.31 ??
    If any one has any idea on this please let me know.
    Thanks
    Neha

    Hi All,
    None of the file names suggested is working.
    I have tried using - MT940_MB_*\.txt , MT940_MB_*.*txt , MT940*.txt
    None of them is able to pick this filename - MT940_MB_20142204060823_1.txt
    Currently I am using generic regular expression which picks all .txt files. - ([^\s]+(\.(txt))$)
    Let me know ur suggestion on this.
    Thanks
    Neha Verma

  • Regular expression fro date time format

    Hi
    im trying to use regexp_like() function in my where clause as
    select 1 from dual where REGEXP_LIKE(''31/12/2003 11:59:59 PM',regular expr pattern)
    I tried this pattern using the following regular expresion which i found on a web site. but this didnt work.
    '^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))(\/)(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M)?)|([01]\d|2[0-3])(:[0-5]\d){1,2})?$'
    can some one suggest me an alternative regular expression for this.
    P.S : i donot want to use to_char/ to_date functions.
    Regards
    Vibhuti

    Hi elic
    I tried with your suggestion yet it didnt work. This is my query
    select 1 from dual where regexp_like('03/02/2000 02:59:59 AM','^(?=[0-9])(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9][0-9])?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?: |$))|(?:2[0-8]|1[0-9]|0?[1-9]))(\/)(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9][0-9])?[0-9][0-9](?:(?= [0-9]) |$))?(((0?[1-9]|1[012])(:[0-5][0-9]){0,2}( [AP]M)?)|([01][0-9]|2[0-3])(:[0-5][0-9]){1,2})?$')
    this should return 1 as output. but its not returning any thing. Im currently working on 10g R2 database. Please help me out, its very critical. Im trying to learn regualr expressions but im unable to crack this code.
    Regards
    Vibhuti

  • Table name for  email-address field

    Hi,
    What is the table name for email address field present in address tab of vd03 transaction

    >
    abap developer wrote:
    > adr6 table is for email address present in contact persons tab in vd03 transaction.I need the table name for email address field present in address tab in vd03 transaction.
    every thing will be stored in ADR6. with Different addressnumbers contact Person address is different and customer address is different.
    there will be 2 different entries in ADR6.

  • How to form a regular expression for matching the xml tag?

    hi i wanted to find the and match the xml tag for that i required to write the regex.
    for exmple i have a string[] str={"<data>abc</data>"};
    i want this string has to be splitted like this <data>, abc and </data>. so that i can read the splitted string value.
    the above is for a small excercise but the tagname and value can be of combination of chars/digits/spl symbols like wise.
    so please help me to write the regular expression for the above requirement

    your suggestion is most appreciable if u can give the startup like how to do this. which parser is to be used and stuff like that

  • Using regular expressions for validation in i18n

    Can we use regular expressions for validation of inputs in a java application taking care of i18N aspects too. Zip code for different locales are different. Can we use regular expressions to validate zipcode inputs from different locales

    hi,
    For that shall i have to create individual patterns for matching the inputs from different locales or a single pattern will do in the case of validating phone nos. around the world, zip codes etc. In case different patterns are required, programmer should have a konwledge of difference in patters for different locales.
    regards
    sdas

Maybe you are looking for

  • JCA flat file read issue

    Hi, We needs to read a flat file and transform it to destination xml format. Then send it to destination file location. Steps we have done: 1. Create JCA adapter and configure the flat file schema 2. Create proxy based on the jca 3. create transforma

  • Report Calculation

    We have a report that calculates monthly interest charges so we can do debit memos each month (#4395 Interest to be Charged). We are currently compounding interest each month - the interest calculation takes the entire past due balance (including pre

  • Faulty color management

    I have Windows XP, home, Epson 2200 printer and CS3. Normally,when preparing to print, the image appears red or magenta in the "preview" window but the print itself is accurate and matches the monitor. Now, the preview image is dark and roughly simil

  • How to coerce the sampling rate??

    I think I found my problem with sampling rate. I'm using a PCI-5122 scope card, and in many of my aquisitions, I'm setting the sample rate to 40MS/s. Apparently, this is not a valid number and the scope reverts to 50 MS/s Later when I try to calculat

  • TS2446 i forgot how i answered my security questions. How do i find the answers or to reset the questions?

    I selected my security questions years ago and i forgot how i answered them. How do i retrieve those answers. Reason being i got a new devices and it asks me for those answers to purchase anything from itunes on it.