I have a string and want to make sure it does not contain digits. Is there a method in the String library that does it or i have to implement it myself?
You could use string.matches
function to check for whether a string contains at-least one digit or not.
string.matches("\\D+");
This will return true
for the strings which won't contain any single digit. \\D
matches any non-digit character. So, \\D+
matches one or more non-digit characters. By passing it to matches
method, it would apply the regex against the whole string.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments