Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex help needed for name validation.

 
Caine Lai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please help me with creating a regex that will validate user input for a name field?

This is what I have so far. See anything missing? The special characters listed are for matching common european characters used in names. I'm not too worried about complete localized names unless there is a simple way to do this.

Current Regex Pattern: ^([A-Za-z�-��-��-� '`\\.,])+

Thanks!
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can catch all letters, accented or not, by using a shorthand like "\p{L}". It's explained in the javadocs for java.util.regex.Pattern.
 
Caine Lai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooooo... yeah that's what I want. Thanks a lot.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic