cancel
Showing results for 
Search instead for 
Did you mean: 

input field validation

Former Member
0 Kudos

Hi

i have a input field with label PIN code which should not be NULL and should accept exactly six digits only and should not even accept Spaces in between, can u tell the required code

Thanks

Durga

Accepted Solutions (0)

Answers (5)

Answers (5)

venkatakalyan_karanam
Active Contributor
0 Kudos

Hi

First check the null

if not call the below method

Use the following method

public boolean isAllNumeric( java.lang.String stringValue )

{

//@@begin isAllNumeric()

boolean isNumeric = false;

isNumeric = Pattern.matches("0-9+", stringValue);

return isNumeric;

//@@end

}

which gives you whether the value is numeric or not.if not throw an error

if yes find the length of the string if not equals 6 throw an error.

Also you can restrict the input field to 6 digits by writing this code in init method.

use try catch block

ISimpleTypeModifiable homeAddrPostalCode = wdContext.wdGetAPI().getModifiableTypeOf ("HomeAddData<nodename>.PostalCode<attribute>");

homeAddrPostalCode.setMaxExternalLength(6);

Regards

Kalyan

nikhil_bose
Active Contributor
0 Kudos

make an attribute of type long and name it as pin. I am creating it in

in wdDoModifyView()

the Root context


    IWDAttributeInfo info = wdContext.getNodeInfo().getAttribute("Pin");
    info.getModifiableSimpleType().setFormat("######");

in the OnAction() where you are validating, put this code


if(wdContext.currentContextElement().getPin() == 0 ) {
 //display empty error message
}
else {
String temp = Long.toString(wdContext.currentContextElement().getPin());
if(temp.length >6 )
// display limit exceeds error message
} // if (temp)
}//else


nikhil

Former Member
0 Kudos

HI

Try this to validate Pin Number Input.


String pin = wdContext.current<node>Element().getPinNo() ;
if(pin.length != 6 ){
wdComponentAPI.getMessageManager().reportException("Invalid Pin No." , true);
} 

Mandeep Virk

Former Member
0 Kudos

Hi,

The following code should help you with your requirements.

if(wdContext.currentContextElement().getMobileNo().length()==6)//For calculating length.

{

int valid_flag=1;

for(int i=0;i<6;i++)

{

int j = wdContext.currentContextElement().getMobileNo().charAt(i);

if(j >=48 && j<=57)

{

valid_flag=1;

}

else

{

valid_flag=2 ;

break;

}

}

if(valid_flag==2)

{

wdComponentAPI.getMessageManager().reportSuccess("Please Enter a valid password");

}

else

{

wdComponentAPI.getMessageManager().reportSuccess("Valid password");

}

}

else

{

wdComponentAPI.getMessageManager().reportSuccess("Please Enter a valid password");

}

Regards,

Sudeep

Former Member
0 Kudos

Hi sudeep

when i enter null value iam geeting null pointer exception

can u tell how to write validation for null value

thanks

durga

Former Member
0 Kudos

Hi Durga,

The input field for which you are entering null, try to read the value form the context of the corresponding field.

After reading this value store this in any String variable and validate,i.e:-

String strVal = wdontext.currentContextElement.getName();

IWDMessageManager messageManager = wdComponentAPI.getMessageManager();

if(strVal.equalsIgnoreCase(null)){

/// print the error msg

messageManager .reportException(("error msg",true);

}

else{

///----needed code

}

Hope that may help you.

Regards,

Deepak

Former Member
0 Kudos

hi

i think this will help u