on 01-13-2009 11:11 AM
Hello,
Please help in creating the simple UDF for a Alphanumeric field contains only numeric characters or mix of numeric and alphanumerics?
Regards,
Jilan
Try like this
String chkValue = input.subString(0,1);
String flag = "false";
if ((chkValue >= 'A' && chkValue <= 'Z') || (chkValue >= 'a' && chkValue <= 'z')) {
flag = "true";
return flag;
}
else
{return flag;}
This will return true if the first character of input is alphabets and false if it is numeric value use this logic according to your requirement.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
you could use this one:
> int i = 0;
> try {
> i = Integer.parseInt (value);
> } catch (Exception E){
> return "0";
> }
> return "1";
Regards
Patrick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Friends, Thanks for the help! Its sorted out!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
my code checks for numeric values.
If you have spaces only at the beginning or the end you could use the trim function first.
If you could also have values like for example 452 45642 55 then you could use the replace function and replace " " with "".
Using the result of these functions as input for the UDF should return your value.
Regards
Patrick
HI ,
You can try with this also.
Input to the UDF is String s and then write the following code...
if(s.matches("\\p{Alnum}+"))
return 1;
else
return 0;
if the value is one then that is Alphanumeric.
Regards
Goli Sridhar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Jilan,
Try with the following code.
String s is a input to the UDF then write the code to following
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
final char c = chars<i>;
if ((c >= 'a') && (c <= 'z')) continue; // lowercase
if ((c >= 'A') && (c <= 'Z')) continue; // uppercase
if ((c >= '0') && (c <= '9')) continue; // numeric
return false;
}
return true;
}
If it is Alphanumeric then it will return true otherwise it return false.
Regards
Goli sridhar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.