on 06-21-2008 5:57 AM
Hi,
How i validate mobile no and email as input filelds. if possible please provide code for same.
Regards,
Gurprit Bhatia
Hi,
You can use the following to validate email ID:
public boolean validateEmailId( java.lang.String emailId )
{
//@@begin validateEmailId()
java.util.regex.Pattern pattern;
String value = null;
boolean isValid = false;
try {
value = emailId.toString();
pattern = java.util.regex.Pattern.compile(expression);
isValid = pattern.matcher(value).matches();
} catch (Exception e) {
}
return isValid;
//@@end
}
static final String expression = "(\\s|>|^)(?!(:|www\\.|\\.))[A-Za-z0-9_.-]+@([A-Za-z0-9_-]+\\.)+[A-Za-z]{2,4}(\\s|\\W|_|<|$)";
To validate mobile number you can use attribute of type long.
thanks & regards,
Manoj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
To validate email input which must contain "@" and "." identifiers
Try this code
//@@begin javadoc:checkEmail()
/** Declared method. */
//@@end
public boolean checkEmail( )
{
//@@begin checkEmail()
// Validate Email entry by user
if( wdContext.currentEmailsDataElement().getToAddress()== null){
return false;
}
String email = wdContext.currentEmailsDataElement().getToAddress();
StringTokenizer mailids = new StringTokenizer(email,";");
while( mailids.hasMoreTokens()){
String id = mailids.nextToken();
String[] splited = id.split("@");
if(splited.length != 2){
return false;
}
if( splited[1].indexOf(".")<=0){
return false;
}
}return true;
//@@end
}
Similarly for Phone no you can check if number exceeds 12 digits raise exception
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);
}
Mandeep Virk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.