This discussion is archived
12 Replies Latest reply: Mar 12, 2010 3:52 PM by 807580 RSS

"Properly" checking if a string is only digits

807580 Newbie
Currently Being Moderated
Hi,
Whats the best way to check a string if it contains any digits only?

Right now I am doing the below code snippet which works if the user types in whole digits. But it obviously fails to give me the
correct boolean when someone types decimals. I could always do a replace all of the decimal but wanted to know if there is an additional "fancy" way of adding more char's to Pattern?

Pattern.matches("^\\d*$", aPossibleNumericString)

So How would I modify the above to give me the below results?
user enters 123 = true
user enters xyz =false
user enters 123.1 = true
user enters xyz123 = false

thanks