cancel
Showing results for 
Search instead for 
Did you mean: 

Validations

jnmurthi
Participant
0 Kudos

hi all,

I need to do validations for some input fields while clicking on "submit" button. One input field contains email id as data. So, what will be the code while I validate that input field, i.e, how to check whether the data entered in the field is valid or not?

Accepted Solutions (1)

Accepted Solutions (1)

former_member189631
Active Contributor
0 Kudos

Hi Narayana,

you can check the inputfiled by writting the appropriate code.

U can write the code for the context u bound to particular Input field. i.e

U have to get the value of that context attribute and check it for "null" or "Empty".

and u can raise the error message by using message manager or

u can bring the window to display error messaged !!..

Regards,

Ramganesan K.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

1) Create a validating action or else make the attibute bound to the text box a calculated one.

2) Inside the action or inside the setter if the attribute is calculated write the follwowing code.

String input = // your attribute

//Checks for email addresses starting with

//inappropriate symbols like dots or @ signs.

Pattern p = Pattern.compile("^
.|^
@");

Matcher m = p.matcher(input);

if (m.find())

System.err.println("Email addresses don't start" +

" with dots or @ signs.");

//Checks for email addresses that start with

//www. and prints a message if it does.

p = Pattern.compile("^www
.");

m = p.matcher(input);

if (m.find()) {

System.out.println("Email addresses don't start" +

" with \"www.\", only web pages do.");

}

p = Pattern.compile("[^A-Za-z0-9
.
@_
-~#]+");

m = p.matcher(input);

StringBuffer sb = new StringBuffer();

boolean result = m.find();

boolean deletedIllegalChars = false;

while(result) {

deletedIllegalChars = true;

m.appendReplacement(sb, "");

result = m.find();

}

// Add the last segment of input to the new String

m.appendTail(sb);

input = sb.toString();

if (deletedIllegalChars) {

System.out.println("It contained incorrect characters" +

" , such as spaces or commas.");

}

http://java.sun.com/developer/technicalArticles/releases/1.4regex/

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

You can as such mention in the context what kind of attribute you require as in string,integer and when you bind it with the input fiels it takes only that type of value.

You can also refer to

As for email you can can validate the format of the email id only. means there should be only 1 "@" and at least a dot (".") in the email id

@ and .

1.check for the indexOf '@' in the email id. if that is -1------ INVALID

2. if 1 is true, take emailid.substring(emailid.indexOf("@")+1) // substring ahead of @. Check indexOf '@' in that substring. - if that is NOT -1 -


INVALID // duplicate @

3. get all the indexOf(".") and check whether anything is not equal to indexOf("@") +1 // immediate . after @

Try it out...

Regards

Radhika Kuthiala

P.S Do award points for encouragement:)

Former Member
0 Kudos

check Input field mandatory:

1.Create an context attribute and it should be available on the current context.

2.Display name is dynamically created text message and fieldContextID is common for every message.

3.you can create the method in component/view controller as checkMandatory(with params what we declare below)

4.this method should where we need to check this method simple add like this.

In Onactoon()

{

checkMandatory(“pleae eneter”,”context value attribute name”);

wdComponentAPI.getMessageManager().raisePendingException();

}

public void checkMandatory( java.lang.String displayName,java.lang.String fieldContextID )

{

//@@begin checkMandatory()

IWDMessageManager messageMgr =wdThis.wdGetAPI().getComponent().getMessageManager();

String attributeValue = wdContext.currentContextElement().getAttributeAsText(fieldContextID);

IWDAttributeInfo attributeInfo =wdContext.getNodeInfo().getAttribute(fieldContextID);

if (attributeValue != null)

attributeValue = attributeValue.trim();

if (attributeValue.length() == 0 && attribute.charAt('@') < 0 ) {

messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,

IMessage<compname>.EMPTY_INPUT,

new Object[] { displayName },

true);

}

5. Go to message editor and add the EMPTY_INPUT key and add your message add over there.

If any prob post ur issues.

Thanks,

Lohi

Former Member
0 Kudos

Lohita

I have written the code like below.

But it is not working.

I have created one contextvar as 'cvar'

and my infutfield value is binded with 'mailid' attr.

public void checkmandatory( java.lang.String cvar )

{

//@@begin checkmandatory()

IWDMessageManager mgr=wdComponentAPI.getMessageManager();

String val=wdContext.currentContextElement() .getAttributeAsText(cvar);

IWDAttributeInfo info=wdContext.getNodeInfo().getAttribute(cvar);

if(val!=null)

val =val.trim();

if (val.length()==0 && val.charAt('@')<0) {

mgr.reportContextAttributeMessage(wdContext.currentContextElement(),info,

IMessageComp_Sample1.EMPTY__INPUT,

new Object[] { cvar },

true);

}

//@@end

}

public void onActionNext(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionNext(ServerEvent)

wdThis.wdFirePlugToview2();

this.checkmandatory("mailid");

wdComponentAPI.getMessageManager().raisePendingException();

//@@end

}