tag:blogger.com,1999:blog-694855878384792308.post485363505518438372..comments2024-03-21T06:26:49.387-07:00Comments on Java67: Java Regular Expression to Check If String contains at least One Digitjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-694855878384792308.post-77409206458998058722021-10-18T21:51:30.125-07:002021-10-18T21:51:30.125-07:00While this work, its not the great solutionWhile this work, its not the great solutionjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-25851214246354250142021-10-18T21:50:51.528-07:002021-10-18T21:50:51.528-07:00which one?which one?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-70341726385575328802018-08-02T03:52:53.161-07:002018-08-02T03:52:53.161-07:00Your regex is incorrect.Your regex is incorrect.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-15441519115770366792017-09-15T12:35:46.961-07:002017-09-15T12:35:46.961-07:00 boolean flag = true;
try {
... boolean flag = true;<br /> <br /> try {<br /> Integer.valueOf(str);<br /> } catch (NumberFormatException nfe) {<br /> flag = false;<br /> }<br /> <br /> return flag;Sureshnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-27582156419731144582017-05-09T06:13:13.980-07:002017-05-09T06:13:13.980-07:00@Anonymous, this is very interesting question. I d...@Anonymous, this is very interesting question. I don't know the answer now, but will try to find out one. I think approach should be just to copy characters from two arrays to a bigger array. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-90544439601680702882017-05-09T06:12:20.635-07:002017-05-09T06:12:20.635-07:00Hello @Anonymous, the right way to check if a Stri...Hello @Anonymous, the <a href="http://javarevisited.blogspot.com/2016/10/how-to-check-if-string-is-numeric-in-Java.html" rel="nofollow">right way to check if a String is numeric in Java</a> is by using a library function like isNumber() or isNumeric(). Your regular expression is ok, but it will fail if String contains + or - character e.g. -234 or +234, if the number contains points e.g. floating point numbers i.e. 101.1 etc, but its correct as far as regular expression is concerned. Even I have used similar pattern to <a href="http://javarevisited.blogspot.sg/2012/10/regular-expression-example-in-java-to-check-String-number.html" rel="nofollow">check if String contains number</a> or not. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-2780687971528928112017-05-08T04:21:29.842-07:002017-05-08T04:21:29.842-07:00how to add two string without using inbuilt librar...how to add two string without using inbuilt library in javaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-27803343150313169612014-08-18T21:48:03.118-07:002014-08-18T21:48:03.118-07:00How do I can find if a String is numric in Java? w...How do I can find if a String is numric in Java? will this work [0-9](.*) ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-68965696019665126812014-07-17T04:48:16.429-07:002014-07-17T04:48:16.429-07:00Slightly better:
private static final Pattern pat...Slightly better:<br /><br />private static final Pattern pattern = Pattern.compile("\\d");<br /><br />public static boolean hasNumber(String str)<br />{<br /> return pattern.matcher(str).find();<br />}Anonymoushttps://www.blogger.com/profile/17217394032641168941noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-88844999216938549202014-05-27T06:41:32.754-07:002014-05-27T06:41:32.754-07:00This is good in one locale only. It cannot be used...This is good in one locale only. It cannot be used as a generic numeric format validation, as each locale has specific requirements (e.g. decimal separator is the comma ',' in many locales)Anonymousnoreply@blogger.com