on 06-23-2008 9:37 AM
hi
i have a input field with label mobile no which should accept only 10 didgits and no SPACE should be given between digits and input field shouldnot be even null,can u help me with the required code for this scenario
thanks
kishore
Hi,
U need to create a string type attribute and bind it to a input field.
On Enter or on ur Submit button u can write following code.
I create a Attribute of string type say mobileno.
if(wdContext.currentContextElement().getMobileno().length()==10)//For calculating length.
{
int k=2;
for(int i=0;i<10;i++)//For valid mobile no(0-9)
{
int j = wdContext.currentContextElement().getMobileno().charAt(i);
if(j>=48 && j<=57)
{
k=1;
}
else
{
k=2 ;
}
}
if(k==2)
{
wdComponentAPI.getMessageManager().reportSuccess("Please Enter a valid number");
}
else
{
//any custom code when no is valid
}
}
else
{
wdComponentAPI.getMessageManager().reportSuccess("Please Enter a valid number");
}
Regards
Surender
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kishore,
use the following code
if( wdcontext.currentcontextElement.getMobileNo()!=null){
String strMobileNumber = wdcontext.currentcontextElement.getMobileNo();
if ( strMobileNumber.indexOf((int)' ') != -1){
// say message "Enter correct mobile number"
} else {
// mobile number is a valid number
}
} else {
// say message "Enter mobile number"
}
Hi
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 10 throw an error.
Also you can restrict the input field to 10 digits by writing this code in init method.
use try catch block
ISimpleTypeModifiable homeAddrPostalCode = wdContext.wdGetAPI().getModifiableTypeOf ("HomeAddData<nodename>.PostalCode<attribute>");
homeAddrPostalCode.setMaxExternalLength(10);
Regards
Kalyan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The following code should help you with your requirements.
if(wdContext.currentContextElement().getMobileNo().length()==10)//For calculating length.
{
int valid_flag=1;
for(int i=0;i<10;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 number");
}
else
{
wdComponentAPI.getMessageManager().reportSuccess("Valid number");
}
}
else
{
wdComponentAPI.getMessageManager().reportSuccess("Please Enter a valid number");
}
Regards,
Sudeep
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Plz try this code
if (wdContext.currentPhoneNoElement().getPhoneNo() > 12)
{
wdComponentAPI.getMessageManager().reportException("Invalid Phone No", true);
}
else if (wdContext.currentPhoneNoElement().getPhoneNo() < 10)
{
wdComponentAPI.getMessageManager().reportException("Invalid Phone No", true);
}
Here the screnario waht i have taken is .
If the user enters a phone no. 919948222298.
Or if he enters 9948222298.
These 2 cond are validated by me.
Thanks & Regards,
Lokesh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kishore,
Create a simpleType of Integer. Go to tab Representation. In the format field fill 9999999999 (10 9's) and External length field enter 10. And save it. Create a context attribute of that simpleType. And bind this attribute to your Inputfield (mobhile no). Validation is taken care by framework itself
Regards,
Siva
Edited by: Siva Rama Krushna on Jun 23, 2008 3:26 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.