José Ferreiro's ホセ フェレイロ (Хосе Ферреиро) research, analysis, management experiences, Information Technology trends, competitive intelligence and life stories...
Friday, April 1, 2011
Earth Hour observed at UN Headquarters (25th March 2011 )

Earth Hour observed at UN Headquarters in New York on Saturday, 25th March 2011 | Picture Credit: Bo Li
Labels:
earth hour,
jose ferreiro,
UN headquarters,
UNECE,
united nations
Thursday, March 31, 2011
Jose Ferreiro at United Nations, we drive by the rules campaign


UNECE member States’ ambassadors reaffirm commitment to road safety by signing “We drive by the rules” poster
Read more...
Road Safety Campaign: “We drive by the rules” poster - United Nations Economic Commission for Europe (UNECE)

Ambassadors and Heads of national delegations attending UNECE’s 64th commission session reaffirmed today their commitment to road safety by signing the poster “We drive by the rules”. This initiative represents a symbolic, personal commitment to the objectives of the Decade of Action for Road Safety (2011-2020) proclaimed by the United Nations General Assembly resolution 64/255 and the importance of road safety in the UNECE region and worldwide.
Labels:
jose ferreiro,
road safety,
UNECE,
united nations,
we drive by the rules
Tuesday, December 7, 2010
Validate textbox in Graphical User Interface containing only numbers

Often it is necessary to validate the input data in the Graphical User Interface when received at the server side. According to the received parameters the server may be not called if the parameters are not in the desired format. This will lead to a saving in the used resources server side. This can be easily done by performing a basic validation on the properties of the object received. The validation proposed here below could be smaller by using regular expressions.
The programming code below just loop on a received string and determines if every character of the string is a digit isDigit(). The loop stops if a character is not a digit and returns false.
/**
*
* @author Jose Ferreiro
*/
public class Main {
/**
* This method checks if a String contains only numbers
*/
public boolean containsOnlyNumbers(String str) {
//It can't contain only numbers if it's null or empty...
if (str == null || str.length() == 0)
return false;
for (int i = 0; i < str.length(); i++) {
//If we find a non-digit character we return false.
if (!Character.isDigit(str.charAt(i)))
return false;
}
return true;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main main = new Main();
System.out.println(main.containsOnlyNumbers("123456"));
System.out.println(main.containsOnlyNumbers("123abc456"));
}
}
OUTPUT of the main method:
True
False
HAPPY CODING
Labels:
isDigit,
java,
jose ferreiro,
jose.ferreiro,
only numbers,
String
Subscribe to:
Posts (Atom)

