I want to validate a string which donot have numeric characters.
If my string is "javaABC" then it must be validated If my string is "java1" then it must not be validated
I want to restrict all the integers.
I want to validate a string which donot have numeric characters.
If my string is "javaABC" then it must be validated If my string is "java1" then it must not be validated
I want to restrict all the integers.
Try this:
String Text = ...;
boolean HasNoNumber = Text.matches("^[^0-9]*$");
'^[^0-9]*$' = From Start(^) to end ($), there are ([...]) only non(^) number(0-9). You can use '\D' as other suggest too ... but this is easy to understand.
See more info here.
Text.matches("[0-9]") means "Text" consists of exactly one digit; you would need to say Text.matches("(?s).*[0-9].*") -- Java's funny that way. OTOH, @NawaMan's regex doesn't really need the anchors: Text.matches("[^0-9]*") or Text.matches("\\D*") work just fine.