Monday, May 7, 2012

isAlpha function in JAVA

This function will return true. if a string contain character value.

like String s="123 Pawan";

public static boolean isAlpha(String s)
{
boolean check=false;
int p=0;

String[] _sc =
{
"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z",

"A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z",

"~","!","@","#","$","%","^","&",
"*","(",")","-","_","+","=",
",",".","/","?","<",">",":",";","'","|","\",","]","}","[","{","*",
};
for(int i=0;i<_sc.length;i++)
{
String sp=_sc[i];
if(s.indexOf(sp)!=-1)
{
p++;
break;
}
}
if(p!=0)
{
check=true;
}
return check;
}

No comments:

Post a Comment