cancel
Showing results for 
Search instead for 
Did you mean: 

Validating Input Field

Former Member
0 Kudos

Hello friends,

I want to validate one input amount field... for that input field the user should not enter characters...If he enter characters then error message should come....

Also give some tutorials for doing this type validation....

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi Murali,

I don't feel, you need to add some special code for validating, whether an input field is entered characters, just bind the input field to a context of type integer. Use the UI element "Message Area". Whenever, the user will enter some character / string type value, an automatic error message, sting "Value <value entered by the user> contains non-numeric characters", will be displayed.

I hope this solves your issue, if you are looking for something else, please revert. I'll be happy to help you.

Cheers!!!

Umang

gill367
Active Contributor
0 Kudos

Hello murali,

For validating an input field against non numeric data, You have two ways .

1. You can bind the onput field to a context attribute of type integer or decimal.

This will give a error message automatically from the framework when the user has entered non

numeric data.But the problem with this method is your navigation is cancelled until you enter the

correct value in the input field.So if this validation is done on second screen of the application it will

not allow the user to even navigate to first screen where the validation is not required. So for solving

this problem we can use the other method.

2. Second Method is you write a utility function and validate the input on event you want this validation

to be done. You can use the following code for this.

//
public boolean IsNotNumeric( java.lang.String Input_String )
  {
    //@@begin IsNotNumeric()

		//@@begin IsNotNumeric()
		//  check for valid numeric strings	

		String strValidChars = "0123456789-";
		char strChar;
		boolean blnResult = false;

		//Check whether the String is numeric
		for (int i = 0; i < Input_String.length() && blnResult == false; i++) {
			strChar = Input_String.charAt(i);
			if (strValidChars.indexOf(strChar) == -1) {
				blnResult = true;
			}
		}
		return blnResult;

    //@@end
  }

Hope it solves your problem

Regards,

Sarbjeet Singh

Former Member
0 Kudos

Hi Murali,

I don't feel, you need some special coding for this. What you need to do, just bind the input field to an attribute if type integer. When ever the user will enter a non-integer value and press a button for processing, an error message will be displayed "Value <Value Entered by the user> contains non-numeric characters".

I hope this solves your issue, if you are looking for something else, please revert. I'll be happy to help you.

Cheers!!!

Umang

Former Member
0 Kudos

HI

check for PATTERN MATCHING code from the google and use that code ,

you can write the code in your action method , or there is another option ,

check the Ascii value for A-Z and a-z and put the if condition , so the you can enter only

numeric values

check this threads

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60db527d-7be4-2a10-0283-e915cfb1...

ravindra_bollapalli2
Active Contributor
0 Kudos

hi murali

refer this link

bvr

Edited by: bvr on May 19, 2009 2:48 PM

former_member214651
Active Contributor
0 Kudos

Hi Murali,

To validate in WD for Java u may use the API IWDMessageManager and its functions for displaying the Error message.

Either u can store the message in the Message Pool and use it or u can directly enter the Error Message in the MessageManager class.

The Syntax is :

1. WdComponentAPI.getMessageManager.reportMessage(<Message>,cancelNavigation(boolean)); or

2. WdComponentAPI.getMessageManager.reportContextAttributeMessager(<CurrentNodeElement>,<AttributeInfoObject>,<MessagePoolObject>,<Object(String for Message)>,<cancelNavigation>);

The First option could be used for displaying the Message, whereas the second option is used when u need to highlight the field which is errenous

Regards,

Poojith M V

Former Member
0 Kudos

Thanks for ur reply .... Actually my problem si to validate the input field .. user has to enter only numbers not characters

Former Member
0 Kudos

Hello Murali,

You can bind the Inputfield to a context attribute of type string ...get the value of the string in the wdDoModifyView() method....and check the ascii value of the characters in the string using <stringname>.charAt(index) function and IWDMessageManager to display the message .....

Hope it helps.

Shikhil