How can I check if an input is a String of alphabet characters..not int double etc etc...
coding101 0 Junior Poster in Training
Recommended Answers
Jump to Postbtw, you would probably need to use Integer.parseInt somewhere in order to do the comparisons..
No.
I would say to simply do
if (!string.trim().matches("^[+-]?[0-9\\.]+$")) { System.out.println("is not a number"); }
The only problem is that that misses things like 001.002.003 (i.e. strings with numbers and multiple …
Jump to PostInteger.parseInt will throw an exception that you will have to catch - not a good practice.
Jump to Postthanks apines. yeah that makes sense. learnt something new today!
Happy to help ;)
Jump to PostNo, that regex will match all of the following strings
123
123.45
+123
+123.45
-123
-123.45unfortunately, as already mentioned, it will also match the following strings
1.2.3
+1.2.3
-1.2.3Also, that original ^ means beginning of String and the $ means end of string to …
All 16 Replies
jon.kiparsky 326 Posting Virtuoso
martin5211 37 Posting Whiz in Training
Dhruv Gairola -3 Junior Poster in Training
masijade 1,351 Industrious Poster Team Colleague Featured Poster
Dhruv Gairola -3 Junior Poster in Training
apines 116 Practically a Master Poster Featured Poster
jon.kiparsky commented: Yep. +1
Dhruv Gairola -3 Junior Poster in Training
apines 116 Practically a Master Poster Featured Poster
jon.kiparsky 326 Posting Virtuoso
masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster
jon.kiparsky 326 Posting Virtuoso
masijade 1,351 Industrious Poster Team Colleague Featured Poster
jon.kiparsky 326 Posting Virtuoso
masijade 1,351 Industrious Poster Team Colleague Featured Poster
Dhruv Gairola -3 Junior Poster in Training
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.