cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate a input fielid which takes in the emailid.

Former Member
0 Kudos

Hi

I have created form in Webdynpro ,which will accept input values from the user .There is one input field which takes the email address of the user .How do i validate this input field as it should only take in the input of the pattern someone@domain.com,if anyother format is entered it should give an error saying it invalid format.

Thanks and Regards

Nishita

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

You can use the following code:

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

}

And expression you can define in others coding part as:

static final String expression = "(
s|>|^)(?!(:|www
.|
.))[A-Za-z0-9_.-]@([A-Za-z0-9_-]
.)+[A-Za-z]{2,4}(
s|
W|_|<|$)";

Pass your email string to this method.

thanks & regards,

Manoj

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi All

I could check the field and it is working properly.Thank you so much.

Thanks and Regards

Nishita

Former Member
0 Kudos

Hi Nishita,

Please check these link. It might help....

Regards

Mrityunjay Kumar

Former Member
0 Kudos

Hi,

You can check the context of type String binded to your input field for email address as follow:

wdContext.currentContextElement().get<attribute>().matches("[A-Z0-9._%+-]@[A-Z0-9.-].");

Regards,

Murtuza

Former Member
0 Kudos

try {

Pattern p=null;

p=Pattern.compile(".@.
.[a-z]+");

Matcher m=p.matcher(name);

if(m.matches())

return true;

else

return false;

} catch (Exception e) {

return false;

}