Re: Strings: how to check for non-numeric chars..
Gordon Beaton wrote:
On Sun, 11 Nov 2007 08:17:02 GMT, Andrew Thompson wrote:
maya wrote:
..
I can't figure out to check whether or not a string contains any
non-numeric characters (to 'pass' my filter it can only contain
chars from 1 to 9, that's it...
What about 0?
yes, of course.. well what happens is img-name can contain zero but NOT
at the first char, i.e., it cannot START with zero.. actually I need to
incorporate this into a larger routine where I do more tests for the
filter.. this is for displaying images in this photo site:
www.francesdelrio.com/photoblog/blog4/photos.jsp.. in a dir like this,
www.mayacove.com/misc/ss_files.gif, only images named from 1.jpg to
99.jpg can pass filter, AND it can't start with zero AND it can't have
any non-numeric chars...
right now only thing I'm missing in whole routine is checking for
non-numeric chars, which, judging from the responses here, it looks like
it might be a bit more complicated than I thought... right now image
'nn.jpg' is passing the filter, but it shouldn't..
routine into which I need to incorporate this:
for (int i=0; i < imgsList.length; i++) {
if (imgsList[i].indexOf(".") != -1) {
posDot = imgsList[i].indexOf(".");
if ( posDot < 3 && imgsList[i].indexOf(".jpg") != -1) {
if (imgsList[i].indexOf("0") != 0) {
vPhotos.addElement(imgsList[i]); // (vPhotos being a Vector..)
}
}
}
}
String[] photos = new String[vPhotos.size()];
vPhotos.toArray(photos);
somewhere in this routine I need to add if substring before '.jpg'
contains a non-numeric char return false..
this is for a JSP, so ideally would like to declare a method
<%! public boolean checkFileName () {
check everything here..
}
%>
then do -- if (checkFileName) -- .. etc..
(this is how I check email address for feedback and signup forms..)
what would be best way to do this..
thank you very much..