0

I wanted to ask if anybody knows how I can check in a string if there is at least a character (either small or big) and if there is at least a number in Java.

Any ideas? Thanks!

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • 3
    Valid, understandable question. How easy and simple it might be, it deserves an answer and no close votes. – Daniel S. Jan 16 '15 at 14:29
  • 5
    I think this would be a valid question if it showed (a) example input strings (b) expected output (c) how the OP has tried to attempt the problem and (d) what the issue with the OP's attempted solution is. – Andy Brown Jan 16 '15 at 14:31
  • @DanielS. - Nothing stops **you** from providing such answer, especially since you see the question as both valid and understandable. – PM 77-1 Jan 16 '15 at 14:34
  • 1
    I doubt that @Panos knows about using regular expressions in a helpful way given his level of skills. Most obviously, most programmers would use regular expression, but this does not help the guy who asked that question! – MWiesner Jan 16 '15 at 14:39
  • 1
    OK, While I'm pretty sure this has been answered multiple times before i'll take a crack. String.isEmpty() will tell you if there is anything in the string at all. Assuming there is, you could use String.indexOf(int ch) where ch is a-z,A-Z,0-9 to check for at least 1 number and letter. But a better Solution is to use String.matches(String regex) with something like [a-zA-Z0-9 _] – Bryan Devaney Jan 16 '15 at 14:42
  • By the way i figured out the solution. In case anybody enters this he can see how i solved it in the following code: if (Pattern.compile("[0-9]").matcher(password).find() &&(Pattern.compile("[a-zA-Z]").matcher(password).find())) –  Jan 19 '15 at 08:31

0 Answers0