Skip to Content
0

UDF to find alphanumeric value

Apr 19, 2017 at 10:34 AM

91

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Andrzej Filusz Apr 19, 2017 at 10:57 AM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

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";
0
Muniyappan Marasamy Apr 19, 2017 at 10:56 AM
0

you can check direct as per this link using standard function.

http://stackoverflow.com/questions/12831719/fastest-way-to-check-a-string-is-alphanumeric-in-java

Share
10 |10000 characters needed characters left characters exceeded