0

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");
1
Contributor
1
Reply
9
Views
4 Years
Discussion Span
Last Post by blue_Student
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.