1) Check mobile number is valid or not
public boolean isValidMobile( final String inMobile )
{
Pattern pattern = Pattern.compile( "[6-9][0-9]{9}" );
Matcher matcher = pattern.matcher( inMobile );
if ( matcher.matches() )
{
return true;
}
else
{
return false;
}
}
{
Pattern pattern = Pattern.compile( "[6-9][0-9]{9}" );
Matcher matcher = pattern.matcher( inMobile );
if ( matcher.matches() )
{
return true;
}
else
{
return false;
}
}
2) Check PIN code is valid or not
public boolean isValidPinCode( final String inStr )
{
final String str = inStr.trim();
final String rule = "[0-9]{6}$";
final Pattern pattern = Pattern.compile( rule );
final Matcher matcher = pattern.matcher( str );
if ( matcher.matches() )
return true;
else
return false;
}
{
final String str = inStr.trim();
final String rule = "[0-9]{6}$";
final Pattern pattern = Pattern.compile( rule );
final Matcher matcher = pattern.matcher( str );
if ( matcher.matches() )
return true;
else
return false;
}
3) Array to string with separator by comma
public String arrayToStringWithComma( String str[] )
{
String processedString = "";
processedString = Arrays.toString( str ).replace( "[", "" ).replace( "]", "" ).replace( " ", "" );
processedString = "," + processedString + ",";
return processedString;
}
{
String processedString = "";
processedString = Arrays.toString( str ).replace( "[", "" ).replace( "]", "" ).replace( " ", "" );
processedString = "," + processedString + ",";
return processedString;
}
4) Remove unused element from start and end of the string
public String removeCommaStartEnd( String str, String element )
{
if ( !str.equal("") && !element.equal("") )
{
str = StringUtils.removeStart( str, "," );
str = StringUtils.removeEnd( str, "," );
str.replace( " ", "" );
}
return str;
}
{
if ( !str.equal("") && !element.equal("") )
{
str = StringUtils.removeStart( str, "," );
str = StringUtils.removeEnd( str, "," );
str.replace( " ", "" );
}
return str;
}
5) String to Array
public String[] commaStringToArray( String str, String sepatator )
{
if ( !str.equal("") && !element.equal("") )
{
str = StringUtils.removeStart( str, sepatator);
str = StringUtils.removeEnd( str, sepatator );
str = str.replace( " "+sepatator+"" );
System.out.println( "string is:" + str );
String str2[] = str.split( sepatator);
return str2;
}
}
{
if ( !str.equal("") && !element.equal("") )
{
str = StringUtils.removeStart( str, sepatator);
str = StringUtils.removeEnd( str, sepatator );
str = str.replace( " "+sepatator+"" );
System.out.println( "string is:" + str );
String str2[] = str.split( sepatator);
return str2;
}
}
Comments
Post a Comment