Skip to Content
avatar image
Former Member

UDF to find alphanumeric value

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 19, 2017 at 10:57 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

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

    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

    Add comment
    10|10000 characters needed characters exceeded