cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to find alphanumeric value

Former Member
0 Kudos

Hi PI Experts,

Please provide me an UDF to find Alphanumeric value.

I have got an UDF to validate integer but i need to validate the input string is Alphanumeric.

UDF to validate integer::

------------------------

int i = 0;

try {

i = Integer.parseInt (a);

} catch (Exception E){

return "0";

}

return "1";

-----------------------

The above UDF gives output as "true" for other than integer value. But it should give output as "true" when it has only alphanumeric value other wise false.

Please provide me an UDF to find whether the input string is Alphanumeric or not.

Thank you.

Chakradhar N

Accepted Solutions (1)

Accepted Solutions (1)

Andrzej_Filusz
Contributor
0 Kudos

Hi Chakradhar,

Please check the code below:

		if (input != null && input.length() > 0) {
			for (int i = 0; i < input.length(); i++) {
				if (!Character.isLetterOrDigit(input.charAt(i)))
					return "0";
			}
			return "1";
		} else 
			return "0";

The question is what should be returned when you have an empty string (last 'return' statement).

Regards,

Andrzej

Former Member
0 Kudos

Hi Andrzej,

Thanks a lot for providing an UDF, sorry for not mentioning for an empty string.

UDF should give output as "true" when it has only alphanumeric value and for empty string, integer it should give out put as ''false''

Hope it is clear now, could you please provide me the updated UDF.

Thank you,

Chakradhar N

Andrzej_Filusz
Contributor
0 Kudos

Here you are:

		if (input != null && input.length() > 0) {
			for (int i = 0; i < input.length(); i++) {
				if (!Character.isLetterOrDigit(input.charAt(i)))
					return "false";
			}
			return "true";
		} else 
			return "false";

Answers (1)

Answers (1)

Muniyappan
Active Contributor
0 Kudos