• Post Reply Bookmark Topic Watch Topic
  • New Topic

isLetterOrDigit  RSS feed

 
Fernando Dominguez
Ranch Hand
Posts: 108
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to create a m,etod that validates if all the caracter of an given String are letter or numbers.

The problem is in isLetterOrDigit; eclipse sais that the method isLetterOrDigit is undefined for the method

private boolean validChar(String cadena)
{
boolean flag = true;
char[] letras = new char[cadena.length()];
letras = cadena.toCharArray();
for(int f = 0; f < letras.length; f++){
char letra =letras[f];
boolean b = isLetterOrDigit(letra);
if(!b)
flag = false;
}
return flag;
}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you define this method?
 
Fernando Dominguez
Ranch Hand
Posts: 108
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the complete class

package com.Utilities.utils;

public class Email {

public static boolean checkMail(String email){

String campo = email.trim();
if (campo.length() > 0){
/*longitud minima*/
if (campo.length() < 6){
return false;
}
/*longitud maxima*/
if (campo.length() > 32){

return false;
}
/*esta la @*/
if ((campo.indexOf("@") < 1) || (campo.indexOf("@") > (campo.length() - 5))) {
return false;
}
/*esta el punto*/
if (campo.indexOf(".") > (campo.length() - 3)){
return false;
}
}
return true;
}

private boolean validChar(String cadena)
{
boolean flag = true;
char[] letras = new char[cadena.length()];
letras = cadena.toCharArray();
for(int f = 0; f < letras.length; f++){
char letra =letras[f];
boolean b = isLetterOrDigit(letra);
if(!b)
flag = false;
}
return flag;
}
}


Thaks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't seem to define this method anywhere. Are you intending to implement it, or are you trying to use the existing static method in the Character class?
 
Fernando Dominguez
Ranch Hand
Posts: 108
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
 
Fernando Dominguez
Ranch Hand
Posts: 108
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have just seen the error , many thanks
 
dharmendra Rathor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//// This is how you can do it using Character class


public class Email {

public static boolean checkMail(String email){

String campo = email.trim();
if (campo.length() > 0){
/*longitud minima*/
if (campo.length() < 6){
return false;
}
/*longitud maxima*/
if (campo.length() > 32){

return false;
}
/*esta la @*/
if ((campo.indexOf("@") < 1) || (campo.indexOf("@") > (campo.length() - 5))) {
return false;
}
/*esta el punto*/
if (campo.indexOf(".") > (campo.length() - 3)){
return false;
}
}
return true;
}

public static void main(String[] args) {
validChar("hello");

}

private static boolean validChar(String cadena)
{
boolean flag = true;
char[] letras = new char[cadena.length()];
letras = cadena.toCharArray();
for(int f = 0; f < letras.length; f++){
char letra =letras[f];
boolean b = Character.isLetterOrDigit(letra);
if(!b)
flag = false;
return flag;
}
return flag;
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!