I am trying to test if my String contains a character ( a-z) (A-Z) and a number (0-9)
package testing;
import java.io.*;
import java.security.*;
import javax.xml.bind.DatatypeConverter;
import java.lang.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Testing extends JPanel
{
public static void main(String[] args)
{
String foo = "abc1";
if (foo.matches(".*[0-9].*") && foo.matches(".*[A-Z].*") && foo.matches(".*[a-z].*"))
{
//contain letters and numbers only
System.out.println("Foo");
}
}
}
I am expecting Foo to be printed out but there seems to be a problem with my regex expression. Can someone help me out ??
Thanks
foodoesn't matchfoo.matches(".*[A-Z].*")