It's not a secret anymore!*
The moose likes Struts and the fly likes Regular Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Regular Expression" Watch "Regular Expression" New topic
Author

Regular Expression

Ashish Bassi
Greenhorn

Joined: Aug 22, 2007
Posts: 11
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
Marshal

Joined: Mar 22, 2005
Posts: 41096
    
  44
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.


Ping & DNS - my free Android networking tools app
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
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 ]

Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
http://forum.java.sun.com/thread.jspa?threadID=5208327
Ashish Bassi
Greenhorn

Joined: Aug 22, 2007
Posts: 11
Thank, i tried it, it works in a stand alone java program, not in struts though, inspite of removing the "\" symbol
prakash chandra
Greenhorn

Joined: Aug 14, 2007
Posts: 24
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 ]

SCJP 6.0
Bhaskar Reddy
Ranch Hand

Joined: Dec 17, 2002
Posts: 52
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.
 
subject: Regular Expression
 
Similar Threads
Doubt on Regular Expression
How can I add error handling facilities to this code?
Validation Using Regular Expression in Javascript
regular expression
help requested with regular expressions