Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression

 
Ashish Bassi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a regular expression to check if the password contains
- atleast 1 Capital letter
- atleast 1 Special character
- atleast 1 numeric
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.
 
arulk pillai
Author
Ranch Hand
Posts: 3373
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following and test it thoroughly:





look at http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html for explanation.
[ August 22, 2007: Message edited by: arulk pillai ]
 
Alan Moore
Ranch Hand
Posts: 262
 
Ashish Bassi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank, i tried it, it works in a stand alone java program, not in struts though, inspite of removing the "\" symbol
 
prakash chandra
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Following is the simple code which will fulfill your requirements. It depends on what special character you want in the Password. You can just append the special character you want in static variable SPECIAL of following code.


[ August 22, 2007: Message edited by: prakash chandra ]
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at RegEx Library.

For your specific req, you may have to search in that, or learn it and build it as per your requirement...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic