Hi, I'm doing an input validation of a String. The number should have a decimal pt, a whole number and a fraction part. It can have a negative sign (-) but not positive sign(+). This is what I've done but when I write --43.05, it prints false.

String n = args[0];
if(n.matches("[-]*([0-9])+[.]([0-9])+")) 
            System.out.println("true");
        else 
            System.out.println("false");

nevermind, I just changed it to "-?[0-9]+[.][0-9]+" and it worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.