• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Regular Expression?

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I use a regular expression to validate the username and password.

It looks like this:

java.util.regex.Pattern p = java.util.regex.Pattern.compile("[0-9a-zA-Z.@_-]{6,50}");

Now I also want to allow the user to use the characters '�', '�', '�', '�', '�', '�'. I have tried to add the character as below, but it does not work?

java.util.regex.Pattern p = java.util.regex.Pattern.compile("[0-9a-zA-Z.@_-������]{6,50}");

What do I do wrong?
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of trying to enumerate all accented letters, you should use character classes like "\p{L}". See the javadocs of java.util.regex.Pattern for more details.

Also, a minus sign must be the last character in your regex if it is taken to be a literal minus sign. You got that right in the first regex, but wrong in the second one.
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnaks alot :-)
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic