cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to find whether the given value is alphanumeric or not

Former Member
0 Kudos

Hello All,

I need to write an udf to find whether the given value is alphanumeric or not.

if the value is only numeric it should return '0'.

if it is any other (it might be the combination of numeric values,alphabets and also speial characters) then it should return '1'.

Thanks

Sai

Accepted Solutions (0)

Answers (3)

Answers (3)

stefan_grube
Active Contributor
0 Kudos

I think this is the shortest code:

if (var1.matches("\\d+")) return "0"; else return "1";

More about patterns here:

Pattern (Java Platform SE 6)

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Swetha,

Please try this udf for your requirement.

String main ="0123456789";

String res = "0";

int  tmp;

for(int i=0;i<inp.length();i++)

{

   tmp = main.indexOf(inp.substring(i,i+1));

   if(tmp == -1)

   {

      res = "1";

      break;

   }

}

return res;

Regards

Vishnu

iaki_vila
Active Contributor
0 Kudos
Former Member
0 Kudos

Hello Vila,

right now i am using this code.

   //write your code here

 

int i = 0;

try {

i = Integer.parseInt (a);

} catch (Exception E){

return "0";

}

return "1";

This is working fine but if the value is beyond the Integer range then there is an issue