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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem using Pattern and Matcher (REGEX)

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not cross post -- as it wastes people's time and effort. Discussions may be continued here...

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

Henry
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic