aspose file tools*
The moose likes Programming Diversions and the fly likes Problem using Pattern and Matcher (REGEX) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Other » Programming Diversions
Reply locked New topic
Author

Problem using Pattern and Matcher (REGEX)

Gurvinder Singh
Greenhorn

Joined: Nov 10, 2008
Posts: 27
Hi i have a problem where i need to put a validation on the text box that it contains only alphabets and numbers. For this i m using pattern and matcher.
I want this validation to be applied to the java file only and not on jsp page page.
My code looks like this

String securityAnswer="afj$%";
Pattern pattern = Pattern.compile("([a-z A-Z 0-9])");
Matcher matcher = pattern.matcher(securityAnswer);
boolean result = matcher.find();


How can i make sure that the text contains only a-z n 0-9 only. becoz whenever i enter any normal text with special characters it accepts on clicking the save button.
I want to write a pattern that returns true only if the securityAnswer string contains alphabets and numbers and not anything else.

Any help will be greatly appreciated.

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18116
    
  39

Please do not cross post -- as it wastes people's time and effort. Discussions may be continued here...

http://www.coderanch.com/t/452045/Java-General-intermediate/java/using-Pattern-n-Matcher-REGEX

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using Pattern and Matcher (REGEX)
 
Similar Threads
email validation using java code ."taking space."
Problem using Pattern n Matcher (REGEX)
How to write a regex to include a text but exclude another text in the one regex?
Check if a String has alphabets
Counting exact matches of substring.