• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 43081
77
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic