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

Problem using Pattern and Matcher (REGEX)

 
Gurvinder Singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
    Bookmark Topic Watch Topic
  • New Topic