on 02-03-2010 5:16 AM
Hi All ,
Need quick and simple logic for numeric validation.
I have to check the field areacode contains values between 0-9 only and it receives only 3digits.Please tell me how to write this logic.
String Area = wdContext.currentSelectedInfotypeElement().getAreac();
if (fpm.getEventData().getEventName().equals(IFPM.EVENT_BACK))
{
Area.matches("0-9");
if(Area.equals("345"))
{
return true;
}
}
java.util.regex.Pattern NUM3 = Pattern.compile("\\d{3}");
java.util.regex.Matcher m = NUM3.matcher(<some string>);
m.matches(); // returns true if <some string> matches the NUM3 pattern
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you are doing something wrong. Try this little test app:
package armin;
public class Pattern1
{
/**
* @param args
*/
public static void main(String[] args)
{
check("");
check("123");
check("abc");
check("1");
check("1ab");
}
private static void check(String s)
{
java.util.regex.Matcher m = NUM3.matcher(s);
System.out.println(s + (m.matches() ? " matches " : " does not match ") + NUM3);
}
private static java.util.regex.Pattern NUM3 = java.util.regex.Pattern.compile("\\d{3}");
}
Armin
A numeric value with 3 digits, using only 0-9 is an integer >0 and <1000, or do I get the question wrong? Why the fuzz?
If you need more control, define a simple type based on integer and set upper and lower bounds. If you also set the NumberFormat, you will even get the leading zeros right ...
hi
check the field areacode contains values between 0-9 only and it receives only 3digits ,
you can use pattern matching code to solve your issue , there are many sample application you can find in google
sdn or even check the java api ,
or other thing you can do is use ASCII values to get only numerix values , if condition between 0 to 9 where
0 to 9 matches ASCII values ,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shruthi,
Try this code hope it will help and do the necessary correction if required.
String expression = "([0-9]+)";
CharSequence inputStr = "345" // supply your input String Here.;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
return matcher.matches();
Let us know if you need any further assist.
Regards
Jeetendra
String expression = "([0-9]+)";
CharSequence inputStr = "345" // supply your input String Here.;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
return matcher.matches();
Requirement is : If i give y7y (alphabet and number) it should return false.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
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.