cancel
Showing results for 
Search instead for 
Did you mean: 

How i validate mobile no and email as input filelds. if possible please pro

Former Member
0 Kudos

Hi,

How i validate mobile no and email as input filelds. if possible please provide code for same.

Regards,

Gurprit Bhatia

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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