on 04-19-2017 11:34 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.