Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I include a ‘dot’ and a ‘hyphen’ in the name section of an email address with

    This is the regular expression I currently have
    Code:
     /^(\w+|\w+.\w+)@(\w+|\w+\-\w+)\.(\w{2,3}|\w{2,3}\.\w{2,3})$/;
    the script dates from about 2006. The script is ok for emails that just contain a ‘dot’ before the @, as in:
    joe.bloggs@home.com

    What needs to be changed in the above script to allow both these types of email?
    joe.bloggs@home.com and
    joe.bloggs-smith@home.com

    Any help greatly appreciated.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,342
    Thanks
    13
    Thanked 349 Times in 345 Posts
    use a character class
    Code:
    (\w+(?:[-.]\w+)*)
    ok, that allows more than exactly one . or -, though
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you Dormilich, your answer was perfect. I have tested the form and it
    now works as I wanted - Much appreciated


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •