• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

First hand at RegEx

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys

I need to do some validation on my system registration screen and decided to use RegEx to validate the email address.

I found a handy little website that allows you to edit and test RegEx to see if you get the correct resulst.
mine should bascially allow for something like

This is what I came up with



It all works fine, apart for some reason it doesn't like it if you put a - in your email!
From what I can see it should allow

but it doesn't!

Confussed!

Any suggestions?

KS
[ June 26, 2008: Message edited by: Keith Seller ]
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try putting the hyphen first, like [-a-zA-Z0-9\\_\\.]

But: If you try to make the regexp overly specific it can happen all too easily that it disallows some proper addresses. I generally use "^\\S+@([-\\w]+\\.){1,4}[a-z]{2,6}$" with a few additional checks (like a valid TLD).

One problems I see with the one you posted is that various valid TLDs that have more than 3 characters (like .travel, .museum and .name) would fail to be recognized.
[ June 26, 2008: Message edited by: Ulf Dittmer ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic